Class: Simp::Metadata::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/simp/metadata/command.rb

Instance Method Summary collapse

Instance Method Details

#helpObject



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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/simp/metadata/command.rb', line 32

def help
  puts 'Usage: simp-metadata [command] [options]'

  # XXX: ToDo: make this dynamic...
  subcommands = [
    [
      'clone',
      'Clones one simp release into another'
    ],
    [
      'component',
      'create, view, or update a component'
    ],
    [
      'delete',
      'deletes a release'
    ],
    [
      'pry',
      'opens up pry debugger'
    ],
    [
      'release',
      'views components of a release'
    ],
    [
      'releases',
      'lists all releases'
    ],
    [
      'save',
      'Saves metadata changes'
    ],
    [
      'script',
      'Execute a script containing multiple commands'
    ],
    [
      'search',
      'searches for components based on attributes'
    ],
    [
      'set-write',
      'Sets which metadata repo to write to if there are multiple'
    ],
    [
      'set-write-url',
      'view/update/create a component'
    ],
    [
      'update',
      'updates a components attributes'
    ]
  ]

  subcommands.each do |components|
    output_string = "#{components[0].ljust(38).rjust(42)}#{components[1]}"
    puts output_string
  end
end

#run(argv) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/simp/metadata/command.rb', line 7

def run(argv)
  command = argv[0]
  argv.shift
  # XXX ToDo: Make this dynamic, just instantiate a class named the subcommand
  if command != ''
    if command == '-h' || command == 'help'
      help
    else
      unless command =~ /^#/
        begin
          cmd = Module.const_get("Simp::Metadata::Commands::#{command.tr('-', '_').capitalize}").new

        rescue
          Simp::Metadata.critical("Unable to find command: #{command}")
          help
          exit 4
        end
        cmd.run(argv)
      end
    end
  else
    help
  end
end