Class: Legion::CLI::Chain

Inherits:
Thor
  • Object
show all
Defined in:
lib/legion/cli/chain_command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/legion/cli/chain_command.rb', line 6

def self.exit_on_failure?
  true
end

Instance Method Details

#create(name) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/legion/cli/chain_command.rb', line 34

def create(name)
  out = formatter
  with_data do
    id = Legion::Data::Model::Chain.insert(name: name)

    if options[:json]
      out.json(id: id, name: name)
    else
      out.success("Chain created: ##{id} (#{name})")
    end
  end
end

#delete(id) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/legion/cli/chain_command.rb', line 49

def delete(id)
  out = formatter
  with_data do
    chain = Legion::Data::Model::Chain[id.to_i]
    unless chain
      out.error("Chain #{id} not found")
      raise SystemExit, 1
    end

    unless options[:confirm]
      out.warn("This will delete chain '#{chain.values[:name]}' and all dependent relationships")
      print '  Continue? [y/N] '
      response = $stdin.gets&.chomp
      unless response&.downcase == 'y'
        out.warn('Aborted')
        return
      end
    end

    chain.delete
    out.success("Chain ##{id} deleted")
  end
end

#listObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/legion/cli/chain_command.rb', line 16

def list
  out = formatter
  with_data do
    rows = Legion::Data::Model::Chain
           .order(Sequel.desc(:id))
           .limit(options[:limit])
           .map do |row|
      v = row.values
      active_str = v[:active] ? out.status('enabled') : out.status('disabled')
      [v[:id].to_s, v[:name].to_s, active_str]
    end

    out.table(%w[id name active], rows)
  end
end