Class: ModuleSync::CLI
Constant Summary
Constants included
from Constants
ModuleSync::Constants::CONF_FILE, ModuleSync::Constants::HOOK_FILE, ModuleSync::Constants::MODULESYNC_CONF_FILE, ModuleSync::Constants::MODULE_CONF_FILE, ModuleSync::Constants::MODULE_FILES_DIR, ModuleSync::Constants::PROJ_ROOT
Instance Method Summary
collapse
Instance Method Details
#commands_available ⇒ Object
20
21
22
23
24
25
|
# File 'lib/modulesync/cli.rb', line 20
def commands_available
[
'update',
'hook',
]
end
|
#defaults ⇒ Object
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/modulesync/cli.rb', line 9
def defaults
{
:namespace => 'puppetlabs',
:branch => 'master',
:git_user => 'git',
:git_provider_address => 'github.com',
:managed_modules_conf => 'managed_modules.yml',
:configs => '.',
}
end
|
#fail(message) ⇒ Object
27
28
29
30
31
|
# File 'lib/modulesync/cli.rb', line 27
def fail(message)
puts @options[:help]
puts message
exit
end
|
#options ⇒ Object
83
84
85
|
# File 'lib/modulesync/cli.rb', line 83
def options
@options
end
|
#parse_opts(args) ⇒ Object
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
|
# File 'lib/modulesync/cli.rb', line 33
def parse_opts(args)
@options = defaults
@options.merge!(Hash.transform_keys_to_symbols(Util.parse_config(MODULESYNC_CONF_FILE)))
@options[:command] = args[0] if commands_available.include?(args[0])
opt_parser = OptionParser.new do |opts|
opts.banner = "Usage: msync update [-m <commit message>] [-c <directory> ] [--noop] [-n <namespace>] [-b <branch>] [-f <filter>] | hook activate|deactivate [-c <directory> ] [-n <namespace>] [-b <branch>]"
opts.on('-m', '--message <msg>',
'Commit message to apply to updated modules') do |msg|
@options[:message] = msg
end
opts.on('-n', '--namespace <url>',
'Remote github namespace (user or organization) to clone from and push to. Defaults to puppetlabs') do |namespace|
@options[:namespace] = namespace
end
opts.on('-c', '--configs <directory>',
'The local directory or remote repository to define the list of managed modules, the file templates, and the default values for template variables.') do |configs|
@options[:configs] = configs
end
opts.on('-b', '--branch <branch>',
'Branch name to make the changes in. Defaults to "master"') do |branch|
@options[:branch] = branch
end
opts.on('-f', '--filter <filter>',
'A regular expression to filter repositories to update.') do |filter|
@options[:filter] = filter
end
opts.on('--noop',
'No-op mode') do |msg|
@options[:noop] = true
end
@options[:help] = opts.help
end.parse!
@options.fetch(:message) do
if @options[:command] == 'update' && ! @options[:noop]
fail("A commit message is required unless using noop.")
end
end
@options.fetch(:command) do
fail("A command is required.")
end
if @options[:command] == 'hook' &&
(! args.include?('activate') && ! args.include?('deactivate'))
fail("You must activate or deactivate the hook.")
end
end
|