Class: RepoTender::CLI::Repo::Remove

Inherits:
Dry::CLI::Command
  • Object
show all
Includes:
GlobalOptions, Helpers
Defined in:
lib/repo_tender/cli/repo.rb

Overview

Remove a tracked repo. Exits 0 with a clear message if the ref was present; exits 1 with “not tracked” if it wasn’t (and the config is untouched in that case).

Instance Method Summary collapse

Methods included from GlobalOptions

included

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



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/repo_tender/cli/repo.rb', line 101

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?

  target = parsed.success
  paths = CLI.make_paths
  config = Config::Store.load(paths.config_file).success

  kept = config.repos.reject { |r| same_repo?(r, target) }
  if kept.size == config.repos.size
    return fail_with(self, "not tracked: #{format_ref(target)}")
  end

  result = Config::Store.update(paths.config_file) do |c|
    Config::Store.with(c, repos: kept)
  end
  if result.failure?
    return fail_with(self, "failed to update config: #{format_failure(result.failure)}")
  end

  out.puts pastel.green("removed: #{format_ref(target)}")
  CLI.record_outcome(Outcome.new(exit_code: 0))
end