Class: SugarJar::Forge

Inherits:
Object
  • Object
show all
Defined in:
lib/sugarjar/forge.rb

Constant Summary collapse

CMD_MAP =
{
  'github' => 'gh',
  'gitlab' => 'glab',
  'forgejo' => 'fj',
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, host) ⇒ Forge

Returns a new instance of Forge.



15
16
17
18
19
# File 'lib/sugarjar/forge.rb', line 15

def initialize(type, host)
  @type = type
  @host = host
  assert_cli_avail!
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/sugarjar/forge.rb', line 7

def type
  @type
end

Instance Method Details

#all_versionsObject



25
26
27
28
29
30
# File 'lib/sugarjar/forge.rb', line 25

def all_versions
  CMD_MAP.values.map do |cli|
    bin = SugarJar::Util.which_nofail(cli)
    _forge_nofail(cli, 'version').stdout if bin
  end.compact
end

#cmdObject



21
22
23
# File 'lib/sugarjar/forge.rb', line 21

def cmd
  @cmd ||= CMD_MAP[@type]
end

#runObject



36
37
38
39
40
# File 'lib/sugarjar/forge.rb', line 36

def run(*)
  s = _forge_nofail(cmd, *)
  s.error!
  s
end

#run_nofailObject



32
33
34
# File 'lib/sugarjar/forge.rb', line 32

def run_nofail(*)
  _forge_nofail(cmd, *)
end

#run_with_system(*args) ⇒ Object



42
43
44
45
# File 'lib/sugarjar/forge.rb', line 42

def run_with_system(*args)
  SugarJar::Log.trace("Running: #{cmd} #{args.join(' ')}")
  system(cmd, *args)
end