Class: RepoTender::CLI::Repo::Add
- Inherits:
-
Dry::CLI::Command
- Object
- Dry::CLI::Command
- RepoTender::CLI::Repo::Add
- Includes:
- GlobalOptions, Helpers
- Defined in:
- lib/repo_tender/cli/repo.rb
Overview
Add a tracked repo. Idempotent on the (host, owner, name) triple: adding the same ref twice prints “already tracked” and exits 0 (does NOT write a duplicate).
Instance Method Summary collapse
Methods included from GlobalOptions
Methods included from Helpers
fail_with, format_failure, format_ref, parse_ref, same_repo?
Instance Method Details
#call(ref:, plain: nil, json: nil, no_color: nil, quiet: nil) ⇒ Object
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 82 83 84 85 86 87 |
# File 'lib/repo_tender/cli/repo.rb', line 57 def call(ref:, plain: nil, json: nil, no_color: nil, quiet: nil, **) mode = UI::Mode.resolve( flags: {plain: plain, json: json, no_color: no_color, quiet: quiet}, env: CLI.env, out: out ) pastel = Pastel.new(enabled: mode.color) parsed = parse_ref(ref) return fail_with(self, parsed.failure) if parsed.failure? new_ref = parsed.success paths = CLI.make_paths config = Config::Store.load(paths.config_file).success if config.repos.any? { |r| same_repo?(r, new_ref) } out.puts pastel.yellow("already tracked: #{format_ref(new_ref)}") return CLI.record_outcome(Outcome.new(exit_code: 0)) end result = Config::Store.update(paths.config_file) do |c| Config::Store.with(c, repos: c.repos + [new_ref]) end if result.failure? return fail_with(self, "failed to update config: #{format_failure(result.failure)}") end out.puts pastel.green("added: #{format_ref(new_ref)}") CLI.record_outcome(Outcome.new(exit_code: 0)) end |