Class: Space::Src::CLI::Org::Add
- Inherits:
-
Dry::CLI::Command
- Object
- Dry::CLI::Command
- Space::Src::CLI::Org::Add
- Includes:
- GlobalOptions, Helpers
- Defined in:
- lib/space_src/cli/org.rb
Instance Method Summary collapse
Methods included from GlobalOptions
Methods included from Helpers
fail_with, format_failure, format_ignored, format_ref, parse_ref, same_org?
Instance Method Details
#call(name:, include_archived: false, include_forks: false, ignored_repos: [], plain: nil, json: nil, no_color: nil, quiet: nil) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/space_src/cli/org.rb', line 81 def call(name:, include_archived: false, include_forks: false, ignored_repos: [], 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(name, include_archived: include_archived, include_forks: include_forks, ignored_repos: ignored_repos) 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.orgs.any? { |o| same_org?(o, new_ref) } out.puts pastel.yellow("already tracked: #{format_ref(new_ref)}" \ " (include_archived=#{new_ref.include_archived}, include_forks=#{new_ref.include_forks})" \ "#{format_ignored(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, orgs: c.orgs + [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)}" \ " (include_archived=#{new_ref.include_archived}, include_forks=#{new_ref.include_forks})" \ "#{format_ignored(new_ref)}") CLI.record_outcome(Outcome.new(exit_code: 0)) end |