Class: Zypper::Upgraderepo::OptParseMain

Inherits:
Object
  • Object
show all
Defined in:
lib/zypper/upgraderepo/cli.rb

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object



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
61
62
63
64
65
66
67
68
69
70
71
72
73
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/zypper/upgraderepo/cli.rb', line 12

def self.parse(args)
  options = OpenStruct.new
  options.operation = :check_current
  options.backup_path = ENV['HOME']
  options.only_enabled = false
  options.alias = true
  options.name = true
  options.hint = true
  options.overrides = {}
  options.version = nil
  options.sort_by = :alias
  options.view = :table
  options.only_repo = nil
  options.timeout = 10.0
  options.exit_on_fail = false
  options.overrides_filename = nil
  options.only_invalid = false
  options.only_protocols = nil
  options.allow_unstable = false

  opt_parser = OptionParser.new do |opt|

    if ENV['ZYPPER_UPGRADEREPO']
      opt.banner = 'Usage: zypper upgraderepo [OPTIONS] [OPERATION]'
    else
      opt.banner = 'Usage: upgraderepo [OPTIONS] [OPERATION]'
    end

    opt.separator ''
    opt.separator 'Operations:'

    opt.on('-b', '--backup <PATH>', 'Create a Tar backup of all the repositories under PATH') do |o|
      options.operation = :backup
      options.only_enabled = false
      options.backup_path = o
    end

    opt.on('-c', '--check-current', 'Check the repositories for the current version (Default)') do |o|
      options.operation = :check_current
    end

    opt.on('-n', '--check-next', 'Check the repositories for the next version') do |o|
      options.operation = :check_next
    end

    opt.on('-C', '--check-for <VERSION>', 'Check for a custom VERSION') do |v|
      options.version = v
      options.operation = :check_for
    end

    opt.on('-l', '--check-last', 'Check the repositories for the last version') do |o|
      options.operation = :check_last
    end

    opt.on('-R', '--reset', 'Reset the repositories to the current OS version.') do |v|
      options.operation = :reset
    end

    opt.on('-t', '--update', 'Update the repositories to the current OS version') do |v|
      options.operation = :update
    end

    opt.on('-u', '--upgrade', 'Upgrade to the next version available') do |o|
      options.operation = :upgrade_to_next
    end

    opt.on('-U', '--upgrade-to <VERSION>', 'Upgrade to a specific VERSION') do |v|
      options.version = v
      options.operation = :upgrade_to
    end

    opt.on('-L', '--upgrade-to-last', 'Upgrade to the last version available') do |o|
      options.operation = :upgrade_to_last
    end

    opt.on('-s', '--status', 'Prints the version status of the current and available releases') do |o|
      options.operation = :status
    end

    opt.separator ''
    opt.separator 'Options:'

    opt.on('--allow-unstable', 'Consider the unstable version as a valid release version') do |o|
      options.allow_unstable = true
    end

    opt.on('--no-name', 'Don\'t upgrade the name') do |o|
      options.name = false
    end

    opt.on('--no-alias', 'Don\'t upgrade the alias') do |o|
      options.alias = false
    end

    opt.on('--no-hint', 'Don\'t find a working URL when the current is invalid') do |o|
      options.hint = false
    end

    opt.on('--override-url <NUMBER>,<URL>', Array, 'Overwrite the repository NUMBER with URL') do |r|
      options.overrides[r[0].to_i] = r[1]
    end

    opt.on('--load-overrides <FILENAME>', 'Check the URLs in the exported FILENAME') do |f|
      options.overrides_filename = f
    end

    opt.on('--exit-on-fail', 'Exit with error when a repository upgrade check fails') do |o|
      options.exit_on_fail = true
    end

    opt.on('--timeout <SECONDS>', "Adjust the waiting SECONDS used to catch an HTTP Timeout Error (Default: #{options.timeout})") do |o|
      options.timeout = o.to_f
    end

    opt.separator ''
    opt.separator 'Filter options:'

    opt.on('--only-enabled', 'Include only the enabled repositories') do |o|
      options.only_enabled = true
    end

    opt.on('--only-repo <NUMBER|NAME|@ALIAS|#URL|&ANY>[,NUMBER2|NAME2|@ALIAS2|#URL2|&ANY2,...]', 'Include only the repositories specified by a NUMBER or a string matching the NAME, @ALIAS, #URL, or &ANY of them') do |o|
      options.only_repo = o.split(',')
    end

    opt.on('--only-invalid', 'Show only invalid repositories') do |o|
      options.only_invalid = true
    end

    opt.on('--only-protocols <PROTOCOL>[,<PROTOCOL2>,...]', Array, "Show only from protocols (supported: #{Request.protocols.join(',')})") do |o|
      options.only_protocols = o
    end

    opt.separator ''
    opt.separator 'View options:'

    opt.on('--sort-by-alias', 'Sort repositories by alias (Default)') do |o|
      options.sort_by = :alias
    end

    opt.on('--sort-by-name', 'Sort repositories by name') do |o|
      options.sort_by = :name
    end

    opt.on('--sort-by-priority', 'Sort repositories by priority') do |o|
      options.sort_by = :priority
    end

    opt.on('--ini', 'Output the result as INI format') do |o|
      options.view = :ini
    end

    opt.on('--quiet', 'Quiet mode, show only error messages') do |o|
      options.view = :quiet
    end

    opt.on('--report', 'View the data as report') do |o|
      options.view = :report
    end

    opt.on('--solved', 'Output as INI with the suggestions for the invalid repositories applied') do |o|
      options.view = :solved
    end

    unless ENV['ZYPPER_UPGRADEREPO']
      opt.separator ''
      opt.separator 'Other:'

      opt.on_tail('-h', '--help', 'Show this message') do |o|
        puts opt
        exit
      end

      opt.on_tail('-v', '--version', 'Show version') do |o|
        puts VERSION
        exit
      end
    end

  end

  if ARGV.empty?
    puts opt_parser; exit
  else
    opt_parser.parse!(ARGV)
  end

  options
end