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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# 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.dup : [:agents] scopes = scopes_for(command, [:scopes]) dry_run = [:dry_run] && command != "status" scope_results = scopes.map do |scope| results = if command == "status" @installer.status(agents: agents, scope: scope) else @installer.public_send(command, agents: agents, scope: scope, dry_run: dry_run, backup: [:backup]) end [scope, results] end print_statuses(scope_results, dry_run ? DRY_RUN_LABELS : STATUS_LABELS) results = scope_results.flat_map { |_scope, scope_result| scope_result } results.each do |result| next unless result.diff @stdout.puts @stdout.puts result.diff end print_backups(results, dry_run) if command == "install" && results.any? { |result| result.status == :manual } @stdout.puts @stdout.puts "Cursor has no global rules file. To apply the instruction globally," @stdout.puts "paste this into Cursor Settings > Rules:" @stdout.puts @stdout.puts Instruction.body end 0 rescue OptionParser::ParseError => e @stderr.puts e. 1 end |