Class: SchwarmCli::Commands::Repos

Inherits:
Base
  • Object
show all
Defined in:
lib/schwarm_cli/commands/repos.rb

Instance Method Summary collapse

Instance Method Details

#createObject



31
32
33
34
35
36
# File 'lib/schwarm_cli/commands/repos.rb', line 31

def create
  handle_errors do
    data = client.repositories.create(**create_attrs)
    output_record(data, fields: { "ID" => "id", "Name" => "name", "Status" => "status" })
  end
end

#delete(id) ⇒ Object



53
54
55
56
57
58
# File 'lib/schwarm_cli/commands/repos.rb', line 53

def delete(id)
  handle_errors do
    client.repositories.destroy(id)
    puts "Repository #{id} deleted."
  end
end

#listObject



9
10
11
12
13
14
# File 'lib/schwarm_cli/commands/repos.rb', line 9

def list
  handle_errors do
    data = client.repositories.list(status: options[:status], query: options[:query])
    output_list(data, columns: [%w[ID id], %w[NAME name], %w[STATUS status]])
  end
end

#pause(id) ⇒ Object



61
62
63
64
65
66
# File 'lib/schwarm_cli/commands/repos.rb', line 61

def pause(id)
  handle_errors do
    data = client.repositories.pause(id)
    puts "Repository #{id} paused (#{data.dig('data', 'status')})."
  end
end

#resume(id) ⇒ Object



69
70
71
72
73
74
# File 'lib/schwarm_cli/commands/repos.rb', line 69

def resume(id)
  handle_errors do
    data = client.repositories.resume(id)
    puts "Repository #{id} resumed (#{data.dig('data', 'status')})."
  end
end

#show(id) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/schwarm_cli/commands/repos.rb', line 17

def show(id)
  handle_errors do
    data = client.repositories.find(id)
    output_record(data, fields: {
                    "ID" => "id", "Name" => "name", "URL" => "url",
                    "Status" => "status", "Base Branch" => "base_branch"
                  })
  end
end

#update(id) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/schwarm_cli/commands/repos.rb', line 41

def update(id)
  handle_errors do
    attrs = {}
    attrs[:name] = options[:name] if options[:name]
    attrs[:base_branch] = options[:base_branch] if options[:base_branch]

    data = client.repositories.update(id, **attrs)
    output_record(data, fields: { "ID" => "id", "Name" => "name", "Status" => "status" })
  end
end