Class: Gush::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/gush/cli.rb,
lib/gush/cli/overview.rb

Defined Under Namespace

Classes: Overview

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gush/cli.rb', line 12

def initialize(*)
  super
  Gush.configure do |config|
    config.gushfile    = options.fetch("gushfile",    config.gushfile)
    config.concurrency = options.fetch("concurrency", config.concurrency)
    config.redis_url   = options.fetch("redis",       config.redis_url)
    config.namespace   = options.fetch("namespace",   config.namespace)
    config.ttl         = options.fetch("ttl",         config.ttl)
  end
  load_gushfile
end

Instance Method Details

#create(name) ⇒ Object



25
26
27
28
29
# File 'lib/gush/cli.rb', line 25

def create(name)
  workflow = client.create_workflow(name)
  puts "Workflow created with id: #{workflow.id}"
  puts "Start it with command: gush start #{workflow.id}"
end

#create_and_start(name, *args) ⇒ Object



39
40
41
42
43
# File 'lib/gush/cli.rb', line 39

def create_and_start(name, *args)
  workflow = client.create_workflow(name)
  client.start_workflow(workflow.id, args)
  puts "Created and started workflow with id: #{workflow.id}"
end

#listObject



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/gush/cli.rb', line 70

def list
  workflows = client.all_workflows
  rows = workflows.map do |workflow|
    [workflow.id, (Time.at(workflow.started_at) if workflow.started_at), workflow.class, {alignment: :center, value: status_for(workflow)}]
  end
  headers = [
    {alignment: :center, value: 'id'},
    {alignment: :center, value: 'started at'},
    {alignment: :center, value: 'name'},
    {alignment: :center, value: 'status'}
  ]
  puts Terminal::Table.new(headings: headers, rows: rows)
end

#rm(workflow_id) ⇒ Object



64
65
66
67
# File 'lib/gush/cli.rb', line 64

def rm(workflow_id)
  workflow = client.find_workflow(workflow_id)
  client.destroy_workflow(workflow)
end

#show(workflow_id) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/gush/cli.rb', line 55

def show(workflow_id)
  workflow = client.find_workflow(workflow_id)

  display_overview_for(workflow) unless options[:skip_overview]

  display_jobs_list_for(workflow, options[:jobs]) unless options[:skip_jobs]
end

#start(*args) ⇒ Object



32
33
34
35
36
# File 'lib/gush/cli.rb', line 32

def start(*args)
  id = args.shift
  workflow = client.find_workflow(id)
  client.start_workflow(workflow, args)
end

#stop(*args) ⇒ Object



46
47
48
49
# File 'lib/gush/cli.rb', line 46

def stop(*args)
  id = args.shift
  client.stop_workflow(id)
end

#viz(name) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/gush/cli.rb', line 85

def viz(name)
  client
  workflow = name.constantize.new
  graph = Graph.new(workflow)
  graph.viz
  Launchy.open graph.path
end