Class: Pushapp::Commands

Inherits:
Object
  • Object
show all
Defined in:
lib/pushapp/commands.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Commands

Returns a new instance of Commands.



11
12
13
14
# File 'lib/pushapp/commands.rb', line 11

def initialize(options = {})
  @options = options
  @logger = Pushapp::Logger.new
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



5
6
7
# File 'lib/pushapp/commands.rb', line 5

def logger
  @logger
end

Class Method Details

.run(command, options = {}) ⇒ Object



7
8
9
# File 'lib/pushapp/commands.rb', line 7

def self.run(command, options = {})
  self.new(options.merge({ command: command })).send(command)
end

Instance Method Details

#execObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/pushapp/commands.rb', line 79

def exec
  if remote
    cmd = (@options[:args] || []).join(' ')
    if cmd.empty?
      puts 'Usage: pushapp exec remote COMMAND'
    else
      begin
        remote.env_run "bundle exec #{cmd}"
      rescue Exception => e
        puts e.message
      end
    end
  else
    logger.error 'Remote not found'
  end
end

#initObject



16
17
18
19
20
21
# File 'lib/pushapp/commands.rb', line 16

def init
  logger.info "Creating an example config file in #{Pushapp::DEFAULT_CONFIG_LOCATION}"
  logger.info 'Customize it to your needs'
  create_config_directory
  write_config_file
end

#list_remotesObject



28
29
30
31
32
33
# File 'lib/pushapp/commands.rb', line 28

def list_remotes
  logger.info 'Known remotes:'
  remotes_table = config.remotes.map {|r| [r.full_name, r.location, r.env]}
  remotes_table.unshift ['Full Name', 'Location', 'ENV']
  logger.shell.print_table(remotes_table)
end

#setupObject



35
36
37
38
39
# File 'lib/pushapp/commands.rb', line 35

def setup
  logger.info 'Setting up remotes'
  remotes.each { |r| r.setup! }
  update_refs
end

#sshObject



71
72
73
74
75
76
77
# File 'lib/pushapp/commands.rb', line 71

def ssh
  if remote
    remote.ssh!
  else
    logger.error 'Remote not found'
  end
end

#tasksObject



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

def tasks
  remotes_list = remotes.empty? ? config.remotes : remotes
  remotes_list.each do |r|
    puts "REMOTE: #{r.full_name}"
    r.tasks.keys.each do |event|
      puts "    EVENT: #{event}"
      r.tasks[event].each do |task|
        puts "        #{task.inspect}"
      end
    end
  end
end

#triggerObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/pushapp/commands.rb', line 54

def trigger
  event = @options[:event]
  local = @options[:local]
  if local
    $stdout.sync = $stderr.sync = true
    logger.info "STARTING TASKS ON EVENT #{event}"
    remotes.each do |r|
      r.tasks_on(event).each do |t|
        logger.info "task: #{t.inspect}"
        Pushapp::Pipe.run(t)
      end
    end
  else
    remotes.each {|r| r.env_run "bundle exec pushapp trigger #{event} #{r.full_name} -l true"}
  end
end

#update_refsObject



23
24
25
26
# File 'lib/pushapp/commands.rb', line 23

def update_refs
  logger.info 'Updating .git/config. Setting up refs to all remotes'
  Pushapp::Git.new.update_tracked_repos(config)
end