Class: DuperVisor::CLI::OptionsDecorator

Inherits:
Struct
  • Object
show all
Defined in:
lib/dupervisor/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject

Returns the value of attribute config

Returns:

  • (Object)

    the current value of config



28
29
30
# File 'lib/dupervisor/cli.rb', line 28

def config
  @config
end

#optsObject

Returns the value of attribute opts

Returns:

  • (Object)

    the current value of opts



28
29
30
# File 'lib/dupervisor/cli.rb', line 28

def opts
  @opts
end

Instance Method Details

#examplesObject



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/dupervisor/cli.rb', line 59

def examples
  opts.separator ''
  opts.separator 'Examples:'.bold.blue.underlined
  opts.separator ''
  opts.separator '    # guess input format, convert YAML format to an INI file'
  opts.separator '    cat config.yml | dv --ini > config.ini'.green
  opts.separator ''
  opts.separator '    # guess input format, convert INI format to a JSON file '
  opts.separator '    dv config.ini --json -o config.json'.green

  opts.separator ''
end

#flagsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/dupervisor/cli.rb', line 30

def flags
  opts.separator 'Options:'.bold.blue.underlined
  opts.separator '  Output Format:'.bold.yellow
  opts.on('--ini', 'Generate an INI file') { config.to = :ini }
  opts.on('--yaml', 'Generate a YAML file') { config.to = :yaml }
  opts.on('--json', 'Generate a JSON file') { config.to = :json }
  opts.separator ''

  opts.separator '  Flags:'.bold.yellow
  opts.on('-o', '--output [FILE]',
          'File to write, STDOUT if none.') do |file|
    config.output = file
  end

  # No argument, shows at tail.  This will print an options summary.
  # Try it and see!
  opts.on('-h', '--help', 'Show this message') do
    puts opts
    exit
  end

  # Another typical switch to print the version.
  opts.on('--version', 'Show version') do
    puts DuperVisor::VERSION
    exit
  end

end

#usageObject



72
73
74
75
76
77
78
79
80
81
# File 'lib/dupervisor/cli.rb', line 72

def usage
  opts.banner = 'Usage:'.bold.blue.underlined + "\n" + '  dv [source-file] [options] '.bold.green
  opts.separator ''
  opts.separator '  Convert between several hierarchical configuration'
  opts.separator '  file formats, such as ' + 'ini, yaml, json.'.bold.green
  opts.separator ''
  opts.separator '  Automatically detects the source format based on either'
  opts.separator '  the file extension, or by attempting to parse STDIN.'
  opts.separator ''
end