Module: Fixman::CommandLine

Includes:
Utilities
Defined in:
lib/fixman/command_line.rb

Constant Summary collapse

URL_TEMPLATE =
{
  symbol: :url,
  prompt: 'Remote repository URL: ',
  label: 'URL',
  type: :mandatory
}
NAME_TEMPLATE =
{
  symbol: :name,
  prompt: 'Repository name: ',
  label: 'Name',
  type: :mandatory
}
OWNER_TEMPLATE =
{
  symbol: :owner,
  prompt: 'Owner: ',
  label: 'Owner',
  type: :mandatory
}
GROUPS_TEMPLATE =
{
  symbol: :groups,
  prompt: 'Groups: ',
  label: 'Groups',
  type: :multiple_choice
}

Instance Method Summary collapse

Methods included from Utilities

#error

Instance Method Details

#get_params(extra_templates, groups) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/fixman/command_line.rb', line 100

def get_params extra_templates, groups
  input = {}
  start_session input, URL_TEMPLATE

  input[:owner], input[:name] =
    Fixman::Repository.extract_owner_and_name input[:url]
  unless input[:owner] && input[:name]
    start_session input, NAME_TEMPLATE
    start_session input, OWNER_TEMPLATE
  end

  unless groups.empty?
    GROUPS_TEMPLATE[:choices] = groups
    start_session input, GROUPS_TEMPLATE
  end

  extra_templates.each do |template|
    start_session input, template
  end

  input[:sha] = Repository.retrieve_head_sha input[:url]

  input
end

#parse_options!(args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fixman/command_line.rb', line 40

def parse_options!(args)
  options = {}
  options[:conf_path] =
    Pathname.new Fixman::Configuration::DEFAULT_CONF_FILE

  parser = OptionParser.new do |opts|
    opts.banner = "Usage: #{NAME} [option]"

    opts.on_tail('-h', '--help', 'Display this message') do
      puts 'help' # TODO
      exit 0
    end

    opts.on('-v', '--version', 'Display the version') do
      puts VERSION
      exit 0
    end

    opts.on('-c', '--configuration-file PATH') do |path|
      options[:conf_path] = Pathname.new path
    end
  end

  begin
    parser.parse! args
  rescue OptionParser::InvalidaOption
    error usage
  end

  options
end

#parse_positional_arguments!(raw_args) ⇒ Object

Options are parsed prior to the positional arguments allowing optional trailing positional arguments.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/fixman/command_line.rb', line 74

def parse_positional_arguments!(raw_args)
  # Error if there are no commands
  error usage if raw_args.size < 1

  command = raw_args.shift.downcase.to_sym
  args = {}

  case command
  when :test, :list, :shortlist, :add
    error usage unless raw_args.size == 0
  when :delete
    error usage unless raw_args.size == 1
    args[:canonical_name] = raw_args.shift
  when :fetch, :upgrade
    args[:groups] = raw_args.map { |group| group.downcase.to_sym }
    raw_args.delete_if {true}
  when :update
    error usage unless [1, 2].include? raw_args.size
    args[:canonical_name], args[:sha] = raw_args.shift 2
  else
    error usage
  end

  [command, args]
end

#usageObject



125
126
127
# File 'lib/fixman/command_line.rb', line 125

def usage
  #TODO
end