Class: HR_Deploy::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/hr_deploy/parser.rb

Instance Method Summary collapse

Instance Method Details

#parse_cmd_argsObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/hr_deploy/parser.rb', line 5

def parse_cmd_args
  command = {}
  command[:action] = nil
  command[:options] = {}

  cmd_options = ARGV

  if cmd_options == [] || cmd_options == ['help']
    command[:action] = :help
    return command
  end

  if cmd_options == ['version']
    command[:action] = :version
    return command
  end

  if cmd_options == ['generate']
    command[:action] = :generate
    return command
  end

  if cmd_options.first == 'deploy'

    deploy_args = cmd_options[1, cmd_options.length]

    if deploy_args_valid?(deploy_args)

      # Don't dry run by default
      dry_run = deploy_args.delete('--dry-run')

      # Confirm actions on deploys by default
      # If '--dry-run' was provided, skip confirmations
      confirm = !(deploy_args.delete('--no-confirm') || dry_run)

      # Run database change actions by default
      db_change = !deploy_args.delete('--no-db-change')

      # If no target specified, it will be set to 'nil'
      target_name = deploy_args.first

      command[:action] = :deploy
      command[:options][:target_name] = target_name
      command[:options][:confirm] = confirm
      command[:options][:dry_run] = dry_run
      command[:options][:db_change] = db_change

      return command
    end
  end

  # Can't parse command
  command[:action] = :help
  command[:options][:failed_parse] = true
  command
end