Class: Sym::App::CLI
Overview
This is the main interface class for the CLI application. It is responsible for parsing user’s input, providing help, examples, coordination of various sub-systems (such as PrivateKey detection), etc.
Besides holding the majority of the application state, it contains two primary public methods: #new
and #run
.
The constructor is responsible for parsing the flags and determining the the application is about to do. It sets up input/output, but doesn’t really execute any encryption or decryption. This happens in the #run
method called immediately after #new
.
{Shh{Shh::App{Shh::App::CLI} module effectively performs the translation of the opts
object (of type Slop::Result) and interpretation of users intentions. It holds on to opts
for the duration of the program.
Responsibility Delegated
The responsibility of determining the private key from various options provided is performed by the PrivateKey::Handler instance. See there for more details.
Subsequently, #run
method handles the finding of the appropriate Sym::App::Commands::BaseCommand subclass to respond to user’s request. Command registry, sorting, command dependencies, and finding them is done by the Coommands module.
User input is handled by the Input::Handler instance, while the output is provided by the procs in the Output classes.
Finally, the Mac OS-X -specific usage of the KeyChain, is encapsulated in a cross-platform way inside the Keychain module.
Instance Attribute Summary collapse
-
#application ⇒ Object
Returns the value of attribute application.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#output_proc ⇒ Object
Returns the value of attribute output_proc.
-
#outputs ⇒ Object
Returns the value of attribute outputs.
Instance Method Summary collapse
- #command ⇒ Object
- #execute ⇒ Object
-
#initialize(argv_original) ⇒ CLI
constructor
A new instance of CLI.
Methods included from CLISlop
Constructor Details
#initialize(argv_original) ⇒ CLI
Returns a new instance of CLI.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/sym/app/cli.rb', line 61 def initialize(argv_original) env_args = ENV[ENV_ARGS_VARIABLE_NAME] begin argv = argv_original.dup argv << env_args.split(' ') if env_args && !(argv.include?('-M') or argv.include?('--no-environment')) argv.flatten! dict = argv.delete('--dictionary') self.opts = parse(argv) command_dictionary if dict rescue StandardError => e error exception: e return end command_no_color(argv_original) if opts[:no_color] self.application = ::Sym::Application.new(opts) select_output_stream end |
Instance Attribute Details
#application ⇒ Object
Returns the value of attribute application.
59 60 61 |
# File 'lib/sym/app/cli.rb', line 59 def application @application end |
#opts ⇒ Object
Returns the value of attribute opts.
59 60 61 |
# File 'lib/sym/app/cli.rb', line 59 def opts @opts end |
#output_proc ⇒ Object
Returns the value of attribute output_proc.
59 60 61 |
# File 'lib/sym/app/cli.rb', line 59 def output_proc @output_proc end |
#outputs ⇒ Object
Returns the value of attribute outputs.
59 60 61 |
# File 'lib/sym/app/cli.rb', line 59 def outputs @outputs end |
Instance Method Details
#command ⇒ Object
94 95 96 |
# File 'lib/sym/app/cli.rb', line 94 def command @command ||= self.application&.command end |
#execute ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/sym/app/cli.rb', line 81 def execute return Sym::App.exit_code if Sym::App.exit_code != 0 result = application.execute case result when Hash self.output_proc = ::Sym::App::Args.new({}).output_class error(result) else self.output_proc.call(result) end Sym::App.exit_code end |