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

#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
end

#sshObject



75
76
77
78
79
80
81
# File 'lib/pushapp/commands.rb', line 75

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

#tasksObject



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/pushapp/commands.rb', line 46

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



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/pushapp/commands.rb', line 59

def trigger
  event = @options[:event]
  local = @options[:local]
  if local
    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

#updateObject



41
42
43
44
# File 'lib/pushapp/commands.rb', line 41

def update
  logger.info 'Updating remotes'
  remotes.each { |r| r.update! }
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