Class: AllInRuby::CLI
- Inherits:
-
Object
- Object
- AllInRuby::CLI
- Defined in:
- lib/all_in_ruby/cli.rb
Constant Summary collapse
- COMMANDS =
%w[install uninstall status].freeze
- STATUS_LABELS =
{ created: "created", updated: "instructions added", already_installed: "already installed, left untouched", removed: "instructions removed", not_installed: "not installed", installed: "installed", manual: "no global rules file; use Cursor Settings > Rules" }.freeze
- DRY_RUN_LABELS =
STATUS_LABELS.merge( created: "would be created", updated: "instructions would be added", already_installed: "would already be covered, no change", removed: "instructions would be removed", not_installed: "not installed, nothing to remove" ).freeze
Instance Method Summary collapse
-
#initialize(stdout: $stdout, stderr: $stderr, installer: Installer.new) ⇒ CLI
constructor
A new instance of CLI.
- #run(argv) ⇒ Object
Constructor Details
#initialize(stdout: $stdout, stderr: $stderr, installer: Installer.new) ⇒ CLI
Returns a new instance of CLI.
27 28 29 30 31 |
# File 'lib/all_in_ruby/cli.rb', line 27 def initialize(stdout: $stdout, stderr: $stderr, installer: Installer.new) @stdout = stdout @stderr = stderr @installer = installer end |
Instance Method Details
#run(argv) ⇒ 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 |
# File 'lib/all_in_ruby/cli.rb', line 33 def run(argv) = { agents: [], scopes: [], dry_run: false, backup: true } parser = build_parser() parser.parse!(argv) command = argv.shift unless COMMANDS.include?(command) @stderr.puts parser return 1 end agents = [:agents].empty? ? Installer::AGENTS : [:agents] scopes = scopes_for(command, [:scopes]) dry_run = [:dry_run] && command != "status" scope_results = results_by_scope(command, agents:, scopes:, dry_run:, backup: [:backup]) print_statuses(scope_results, dry_run ? DRY_RUN_LABELS : STATUS_LABELS) results = scope_results.flat_map { |_scope, scope_result| scope_result } print_diffs(results) print_backups(results, dry_run) print_manual_instruction(command, results) 0 rescue OptionParser::ParseError => e @stderr.puts e. 1 end |