Module: RepoTender::CLI::Org::Helpers
Class Method Summary collapse
- .fail_with(cmd, msg) ⇒ Object
- .format_failure(f) ⇒ Object
- .format_ref(o) ⇒ Object
-
.parse_ref(name, include_archived: false, include_forks: false) ⇒ Object
Parse an org ref string.
- .same_org?(a, b) ⇒ Boolean
Class Method Details
.fail_with(cmd, msg) ⇒ Object
54 55 56 57 |
# File 'lib/repo_tender/cli/org.rb', line 54 def fail_with(cmd, msg) cmd.send(:err).puts msg RepoTender::CLI.record_outcome(Outcome.new(exit_code: 1, message: msg)) end |
.format_failure(f) ⇒ Object
52 |
# File 'lib/repo_tender/cli/org.rb', line 52 def format_failure(f) = f.is_a?(Hash) ? f.inspect : f.to_s |
.format_ref(o) ⇒ Object
51 |
# File 'lib/repo_tender/cli/org.rb', line 51 def format_ref(o) = "#{o.host}/#{o.name}" |
.parse_ref(name, include_archived: false, include_forks: false) ⇒ Object
Parse an org ref string. Accepts “github.com/socketry” or bare “socketry” (defaults host to github.com). Anything with 3+ parts is rejected (org has only host + name).
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/repo_tender/cli/org.rb', line 23 def parse_ref(name, include_archived: false, include_forks: false) parts = name.to_s.split("/") case parts.length when 1 org = parts[0] return Dry::Monads::Failure("invalid org reference: empty name in #{name.inspect}") if org.empty? Dry::Monads::Success(Config::OrgRef.new( host: Config::DEFAULT_HOST, name: org, include_archived: include_archived, include_forks: include_forks )) when 2 host, n = parts return Dry::Monads::Failure("invalid org reference: empty host in #{name.inspect}") if host.empty? return Dry::Monads::Failure("invalid org reference: empty name in #{name.inspect}") if n.empty? Dry::Monads::Success(Config::OrgRef.new( host: host, name: n, include_archived: include_archived, include_forks: include_forks )) else Dry::Monads::Failure("invalid org reference: #{name.inspect} (expected \"<name>\" or \"<host>/<name>\")") end end |
.same_org?(a, b) ⇒ Boolean
50 |
# File 'lib/repo_tender/cli/org.rb', line 50 def same_org?(a, b) = a.host == b.host && a.name == b.name |