Class: Buildbox::CLI
- Inherits:
-
Object
- Object
- Buildbox::CLI
- Defined in:
- lib/buildbox/cli.rb
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
Instance Method Summary collapse
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
- #parse ⇒ Object
Constructor Details
#initialize(argv) ⇒ CLI
Returns a new instance of CLI.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/buildbox/cli.rb', line 7 def initialize(argv) @argv = argv @commands = {} = {} @commands['worker:start'] = OptionParser.new do |opts| opts. = "Usage: buildbox worker:start" opts.on("--help", "You're looking at it.") do puts @commands['worker:start'] exit end end @commands['worker:setup'] = OptionParser.new do |opts| opts. = "Usage: buildbox worker:setup [token]" opts.on("--help", "You're looking at it.") do puts @commands['worker:setup'] exit end end @commands['version'] = OptionParser.new do |opts| opts. = "Usage: buildbox version" end end |
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
5 6 7 |
# File 'lib/buildbox/cli.rb', line 5 def argv @argv end |
Instance Method Details
#parse ⇒ Object
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 |
# File 'lib/buildbox/cli.rb', line 35 def parse global.order! command = @argv.shift if command if @commands.has_key?(command) @commands[command].parse! else puts "`#{command}` is an unknown command" exit 1 end if command == "version" puts Buildbox::VERSION exit end if command == "worker:start" Buildbox::Worker.new(Buildbox.config.worker_access_token).start elsif command == "worker:setup" if @argv.length == 0 puts "No token provided" exit 1 end access_token = @argv.first Buildbox.config.update(:worker_access_token => access_token) puts "Successfully added worker access token" puts "You can now start the worker with `buildbox worker:start`" end else puts global.help end end |