Class: Automatic::CLI
- Inherits:
-
Object
- Object
- Automatic::CLI
- Defined in:
- lib/automatic/cli.rb
Constant Summary collapse
- EXIT_SUCCESS =
0- EXIT_FAILURE =
1- EXIT_USAGE =
2- DEFAULT_ROOT_DIR =
The installation root: the directory holding plugins/, config/ and db/.
File.('../..', __dir__)
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(root_dir: DEFAULT_ROOT_DIR, stdout: $stdout, stderr: $stderr) ⇒ CLI
constructor
A new instance of CLI.
-
#run(argv) ⇒ Object
Returns the process exit status.
Constructor Details
#initialize(root_dir: DEFAULT_ROOT_DIR, stdout: $stdout, stderr: $stderr) ⇒ CLI
Returns a new instance of CLI.
35 36 37 38 39 |
# File 'lib/automatic/cli.rb', line 35 def initialize(root_dir: DEFAULT_ROOT_DIR, stdout: $stdout, stderr: $stderr) @root_dir = root_dir @stdout = stdout @stderr = stderr end |
Class Method Details
.run(argv, **options) ⇒ Object
31 32 33 |
# File 'lib/automatic/cli.rb', line 31 def self.run(argv, **) new(**).run(argv) end |
Instance Method Details
#run(argv) ⇒ Object
Returns the process exit status. --help and --version, and a subcommand invoked without its argument, finish early by throwing :automatic_exit.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/automatic/cli.rb', line 43 def run(argv) catch(:automatic_exit) do argv = argv.dup recipe_path = nil parser = build_parser { |path| recipe_path = path } begin parser.order!(argv) rescue OptionParser::ParseError => e @stderr.puts e. @stderr.puts parser.help throw :automatic_exit, EXIT_USAGE end next run_recipe(recipe_path) unless recipe_path.to_s.empty? next usage(parser) if argv.empty? run_subcommand(argv) end end |