Class: Pantry::CLI
Overview
Pantry’s Command Line Interface.
Instance Attribute Summary
Attributes inherited from Client
Instance Method Summary collapse
-
#initialize(command_line, **args) ⇒ CLI
constructor
A new instance of CLI.
-
#perform(options, arguments) ⇒ Object
Given the parsed options and the arguments left over, figure out what Command was requested, build up the appropriate structures and start the communication process.
- #prepare_local_pantry_root ⇒ Object
- #process_global_options(options) ⇒ Object
-
#receive_message(message) ⇒ Object
All messages received by this client are assumed to be responses from previous commands.
-
#request(filter, command, options) ⇒ Object
Fire off the requested Command.
- #run ⇒ Object
Methods inherited from Client
#receive_file, #send_file, #send_message, #send_request, #shutdown
Constructor Details
#initialize(command_line, **args) ⇒ CLI
6 7 8 9 10 11 |
# File 'lib/pantry/cli.rb', line 6 def initialize(command_line, **args) @command_line = Pantry::CommandLine.new(command_line) args[:identity] ||= ENV["USER"] super(**args) end |
Instance Method Details
#perform(options, arguments) ⇒ Object
Given the parsed options and the arguments left over, figure out what Command was requested, build up the appropriate structures and start the communication process.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/pantry/cli.rb', line 65 def perform(, arguments) command_info, = @command_line.triggered_command if command_info client_filter = Pantry::Communication::ClientFilter.new( application: ['application'], environment: ['environment'], roles: ['roles'] ) command = command_info[:class].new(*arguments) = .merge() request(client_filter, command, ) else $stderr.puts "I don't know the #{arguments.first} command" end end |
#prepare_local_pantry_root ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/pantry/cli.rb', line 25 def prepare_local_pantry_root if Pantry.config.root_dir.nil? # TODO Find a .pantry up the chain vs building one Pantry.config.root_dir = File.join(Dir.pwd, ".pantry") FileUtils.mkdir_p(Pantry.root) end end |
#process_global_options(options) ⇒ Object
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 |
# File 'lib/pantry/cli.rb', line 33 def () if ["verbose"] Pantry.config.log_level = :info Pantry.config.refresh end if ["debug"] Pantry.config.log_level = :debug Pantry.config.refresh end if server_host = ["host"] Pantry.config.server_host = server_host end if curve_key_file = ["curve-key-file"] Pantry.config.security = "curve" copy_keys_file_into_pantry_root(curve_key_file) end if ["version"] Pantry.ui.say Pantry::VERSION terminate return false end true end |
#receive_message(message) ⇒ Object
All messages received by this client are assumed to be responses from previous commands.
114 115 116 117 118 |
# File 'lib/pantry/cli.rb', line 114 def () if @command @command.receive_response() end end |
#request(filter, command, options) ⇒ Object
Fire off the requested Command.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/pantry/cli.rb', line 85 def request(filter, command, ) @command = command @command.client = self # We don't use send_request here because we don't want to deal with the # wait-list future system. This lets command objects handle responses # as they come back to the CLI as the command sees fit. # If the command isn't meant directly for the Server, the Server will always # respond first with the list of clients who will be executing the command # and responding with the results. See Pantry::Commands::Echo for an example of how # to work with this flow. begin = @command.() .to = filter.stream .requires_response! () @command.wait_for_finish copy_full_keys_back_to_curve_key_file rescue Exception => ex Pantry.ui.say("Error: #{ex.message}") Pantry.logger.debug(ex.backtrace.join("\n")) end end |
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pantry/cli.rb', line 13 def run prepare_local_pantry_root , arguments = @command_line.parse! if && () super perform(, arguments) end terminate end |