automate-it 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.hgignore +10 -0
- data/.loadpath +5 -0
- data/.project +17 -0
- data/CHANGES.txt +314 -0
- data/Hoe.rake +40 -0
- data/Manifest.txt +164 -0
- data/README.txt +40 -0
- data/Rakefile +256 -0
- data/TESTING.txt +57 -0
- data/TODO.txt +50 -0
- data/TUTORIAL.txt +391 -0
- data/automate-it.gemspec +25 -0
- data/bin/ai +3 -0
- data/bin/aifield +75 -0
- data/bin/aissh +93 -0
- data/bin/aitag +134 -0
- data/bin/automateit +133 -0
- data/docs/friendly_errors.txt +50 -0
- data/docs/previews.txt +86 -0
- data/examples/basic/Rakefile +26 -0
- data/examples/basic/config/automateit_env.rb +16 -0
- data/examples/basic/config/fields.yml +3 -0
- data/examples/basic/config/tags.yml +7 -0
- data/examples/basic/dist/README.txt +9 -0
- data/examples/basic/dist/myapp_server.erb +30 -0
- data/examples/basic/install.log +15 -0
- data/examples/basic/lib/README.txt +10 -0
- data/examples/basic/recipes/README.txt +4 -0
- data/examples/basic/recipes/install.rb +61 -0
- data/examples/basic/recipes/uninstall.rb +6 -0
- data/gpl.txt +674 -0
- data/helpers/cpan_wrapper.pl +220 -0
- data/helpers/which.cmd +7 -0
- data/lib/automateit.rb +55 -0
- data/lib/automateit/account_manager.rb +114 -0
- data/lib/automateit/account_manager/base.rb +138 -0
- data/lib/automateit/account_manager/etc.rb +128 -0
- data/lib/automateit/account_manager/nscd.rb +33 -0
- data/lib/automateit/account_manager/passwd_expect.rb +40 -0
- data/lib/automateit/account_manager/passwd_pty.rb +69 -0
- data/lib/automateit/account_manager/posix.rb +138 -0
- data/lib/automateit/address_manager.rb +88 -0
- data/lib/automateit/address_manager/base.rb +171 -0
- data/lib/automateit/address_manager/bsd.rb +28 -0
- data/lib/automateit/address_manager/freebsd.rb +59 -0
- data/lib/automateit/address_manager/linux.rb +42 -0
- data/lib/automateit/address_manager/openbsd.rb +66 -0
- data/lib/automateit/address_manager/portable.rb +37 -0
- data/lib/automateit/address_manager/sunos.rb +34 -0
- data/lib/automateit/cli.rb +85 -0
- data/lib/automateit/common.rb +65 -0
- data/lib/automateit/constants.rb +35 -0
- data/lib/automateit/download_manager.rb +48 -0
- data/lib/automateit/edit_manager.rb +321 -0
- data/lib/automateit/error.rb +10 -0
- data/lib/automateit/field_manager.rb +103 -0
- data/lib/automateit/interpreter.rb +631 -0
- data/lib/automateit/package_manager.rb +257 -0
- data/lib/automateit/package_manager/apt.rb +27 -0
- data/lib/automateit/package_manager/cpan.rb +101 -0
- data/lib/automateit/package_manager/dpkg.rb +54 -0
- data/lib/automateit/package_manager/egg.rb +64 -0
- data/lib/automateit/package_manager/gem.rb +201 -0
- data/lib/automateit/package_manager/pear.rb +95 -0
- data/lib/automateit/package_manager/pecl.rb +80 -0
- data/lib/automateit/package_manager/portage.rb +69 -0
- data/lib/automateit/package_manager/yum.rb +65 -0
- data/lib/automateit/platform_manager.rb +49 -0
- data/lib/automateit/platform_manager/darwin.rb +30 -0
- data/lib/automateit/platform_manager/debian.rb +26 -0
- data/lib/automateit/platform_manager/freebsd.rb +29 -0
- data/lib/automateit/platform_manager/gentoo.rb +26 -0
- data/lib/automateit/platform_manager/lsb.rb +44 -0
- data/lib/automateit/platform_manager/openbsd.rb +28 -0
- data/lib/automateit/platform_manager/struct.rb +80 -0
- data/lib/automateit/platform_manager/sunos.rb +39 -0
- data/lib/automateit/platform_manager/uname.rb +29 -0
- data/lib/automateit/platform_manager/windows.rb +40 -0
- data/lib/automateit/plugin.rb +7 -0
- data/lib/automateit/plugin/base.rb +32 -0
- data/lib/automateit/plugin/driver.rb +256 -0
- data/lib/automateit/plugin/manager.rb +224 -0
- data/lib/automateit/project.rb +493 -0
- data/lib/automateit/root.rb +17 -0
- data/lib/automateit/service_manager.rb +93 -0
- data/lib/automateit/service_manager/chkconfig.rb +39 -0
- data/lib/automateit/service_manager/rc_update.rb +37 -0
- data/lib/automateit/service_manager/sysv.rb +139 -0
- data/lib/automateit/service_manager/update_rcd.rb +35 -0
- data/lib/automateit/shell_manager.rb +316 -0
- data/lib/automateit/shell_manager/base_link.rb +67 -0
- data/lib/automateit/shell_manager/link.rb +24 -0
- data/lib/automateit/shell_manager/portable.rb +523 -0
- data/lib/automateit/shell_manager/symlink.rb +32 -0
- data/lib/automateit/shell_manager/which_base.rb +30 -0
- data/lib/automateit/shell_manager/which_unix.rb +16 -0
- data/lib/automateit/shell_manager/which_windows.rb +20 -0
- data/lib/automateit/tag_manager.rb +127 -0
- data/lib/automateit/tag_manager/struct.rb +121 -0
- data/lib/automateit/tag_manager/tag_parser.rb +93 -0
- data/lib/automateit/tag_manager/yaml.rb +29 -0
- data/lib/automateit/template_manager.rb +56 -0
- data/lib/automateit/template_manager/base.rb +181 -0
- data/lib/automateit/template_manager/erb.rb +17 -0
- data/lib/ext/metaclass.rb +17 -0
- data/lib/ext/object.rb +18 -0
- data/lib/ext/shell_escape.rb +7 -0
- data/lib/hashcache.rb +22 -0
- data/lib/helpful_erb.rb +63 -0
- data/lib/inactive_support.rb +53 -0
- data/lib/inactive_support/basic_object.rb +6 -0
- data/lib/inactive_support/clean_logger.rb +127 -0
- data/lib/inactive_support/core_ext/array/extract_options.rb +19 -0
- data/lib/inactive_support/core_ext/blank.rb +50 -0
- data/lib/inactive_support/core_ext/class/attribute_accessors.rb +48 -0
- data/lib/inactive_support/core_ext/class/inheritable_attributes.rb +140 -0
- data/lib/inactive_support/core_ext/enumerable.rb +63 -0
- data/lib/inactive_support/core_ext/hash/keys.rb +54 -0
- data/lib/inactive_support/core_ext/module/aliasing.rb +70 -0
- data/lib/inactive_support/core_ext/numeric/time.rb +91 -0
- data/lib/inactive_support/core_ext/string/inflections.rb +153 -0
- data/lib/inactive_support/core_ext/symbol.rb +14 -0
- data/lib/inactive_support/core_ext/time/conversions.rb +96 -0
- data/lib/inactive_support/duration.rb +96 -0
- data/lib/inactive_support/inflections.rb +53 -0
- data/lib/inactive_support/inflector.rb +282 -0
- data/lib/nested_error.rb +33 -0
- data/lib/nitpick.rb +33 -0
- data/lib/queued_logger.rb +68 -0
- data/lib/tempster.rb +250 -0
- data/misc/index_gem_repository.rb +304 -0
- data/misc/setup_egg.rb +12 -0
- data/misc/setup_gem_dependencies.sh +6 -0
- data/misc/setup_rubygems.sh +21 -0
- metadata +279 -0
data/automate-it.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "automate-it"
|
3
|
+
s.version = '0.9.0'
|
4
|
+
s.default_executable = "automateit"
|
5
|
+
s.license = 'GNU-GPL'
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Igal Koshevoy", "Pavel Novotny"]
|
9
|
+
s.date = %q{2013-05-16}
|
10
|
+
s.description = %q{AutomateIt is an open source tool for automating the setup and maintenance of servers, applications and their dependencies. This is updated fork.}
|
11
|
+
s.email = %q{fandisek@gmail.com}
|
12
|
+
s.homepage = %q{http://rubygems.org/gems/better-automateit}
|
13
|
+
s.rubygems_version = %q{1.6.2}
|
14
|
+
s.summary = %q{Fork of AutomateIt}
|
15
|
+
s.bindir = 'bin'
|
16
|
+
|
17
|
+
s.add_dependency 'hoe'
|
18
|
+
s.add_dependency 'open4'
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
|
25
|
+
end
|
data/bin/ai
ADDED
data/bin/aifield
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# XXX What can go wrong with this loading approach?
|
4
|
+
libdir = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
|
5
|
+
if File.directory?(libdir) and File.exists?(File.join(libdir, "automateit.rb"))
|
6
|
+
$LOAD_PATH.unshift(libdir)
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rubygems'
|
10
|
+
require 'optparse'
|
11
|
+
require 'automateit'
|
12
|
+
|
13
|
+
OptionParser.new do |parser|
|
14
|
+
PROG = File.basename($0)
|
15
|
+
opts = {}
|
16
|
+
parser.banner = <<EOB
|
17
|
+
#{PROG} - tool for querying AutomateIt fields
|
18
|
+
|
19
|
+
Usage: #{PROG} [options] query
|
20
|
+
|
21
|
+
Examples:
|
22
|
+
# Load 'myproject' and get value of 'user' field in 'myapp' hash:
|
23
|
+
#{PROG} -p myproject myapp#user
|
24
|
+
|
25
|
+
# Same but using environmental variable to specify project:
|
26
|
+
AUTOMATEIT_PROJECT=myproject
|
27
|
+
#{PROG} myapp#user
|
28
|
+
|
29
|
+
# Dump the 'myapp' hash contents as YAML
|
30
|
+
#{PROG} -y myapp#user
|
31
|
+
|
32
|
+
Options:
|
33
|
+
EOB
|
34
|
+
parser.on("-p", "--project PATH", "Set project path") do |v|
|
35
|
+
opts[:project] = v
|
36
|
+
end
|
37
|
+
|
38
|
+
parser.on("-Y", "--yaml", "Dump as YAML") do |v|
|
39
|
+
opts[:yaml] = v
|
40
|
+
end
|
41
|
+
|
42
|
+
parser.on("-a", "--add TAGS", "Add list of space separated tags") do |v|
|
43
|
+
opts[:tags] = [v.split].flatten
|
44
|
+
end
|
45
|
+
|
46
|
+
parser.on("-v", "--version", "Display version") do |v|
|
47
|
+
puts AutomateIt::VERSION
|
48
|
+
exit 0
|
49
|
+
end
|
50
|
+
|
51
|
+
parser.on("-h", "--help", "Display this help message") do |v|
|
52
|
+
puts parser
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
|
56
|
+
args = parser.parse!.dup
|
57
|
+
|
58
|
+
# Clear ARGV so that IRB doesn't try to parse our options
|
59
|
+
opts[:args] = args
|
60
|
+
ARGV.clear
|
61
|
+
|
62
|
+
query = args.first unless args.empty?
|
63
|
+
|
64
|
+
interpreter = AutomateIt.new(:project => opts[:project])
|
65
|
+
result = interpreter.lookup(query)
|
66
|
+
if result.nil?
|
67
|
+
puts result.inspect
|
68
|
+
exit 1
|
69
|
+
elsif opts[:yaml]
|
70
|
+
puts result.to_yaml
|
71
|
+
else
|
72
|
+
puts result.is_a?(String) ? result : result.inspect
|
73
|
+
end
|
74
|
+
exit 0
|
75
|
+
end
|
data/bin/aissh
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# XXX What can go wrong with this loading approach?
|
4
|
+
libdir = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
|
5
|
+
if File.directory?(libdir) and File.exists?(File.join(libdir, "automateit.rb"))
|
6
|
+
$LOAD_PATH.unshift(libdir)
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rubygems'
|
10
|
+
require 'optparse'
|
11
|
+
require 'automateit'
|
12
|
+
include AutomateIt::Constants
|
13
|
+
|
14
|
+
OptionParser.new do |parser|
|
15
|
+
PROG = File.basename($0)
|
16
|
+
opts = {}
|
17
|
+
parser.banner = <<EOB
|
18
|
+
#{PROG} - tool for running command via SSH on hosts matching AutomateIt tags
|
19
|
+
|
20
|
+
Usage: #{PROG} [options] [arguments...]
|
21
|
+
|
22
|
+
IMPORTANT:
|
23
|
+
#{PROG} can only match against tags specified in tags.yml. It cannot
|
24
|
+
match against automatically generated tags like the OS, architecture and such
|
25
|
+
which are created at runtime by PlatformManager or AddressManager. So if you
|
26
|
+
want to run a command against all Ubuntu servers, you must define them
|
27
|
+
explicitly in tags.yml.
|
28
|
+
|
29
|
+
Examples:
|
30
|
+
# Read tags from project in current directory and run "ls" on all hosts
|
31
|
+
# tagged with "apache_servers" or "rails_servers":
|
32
|
+
#{PROG} --project . 'apache_servers | rails_servers' ls
|
33
|
+
|
34
|
+
# Preview SSH commands needed to run "ls" on "apache_servers":
|
35
|
+
#{PROG} -p . -n apache_servers ls
|
36
|
+
|
37
|
+
# Pass arguments to "ls", rather than #{PROG}:
|
38
|
+
#{PROG} -p . -n apache_servers -- ls -la
|
39
|
+
|
40
|
+
# Same as previous but using a quoted string:
|
41
|
+
#{PROG} -p . -n apache_servers 'ls -la'
|
42
|
+
|
43
|
+
# Execute a command which requires the target server to redirect output:
|
44
|
+
#{PROG} -p . -n apache_servers 'ps -ef | grep apache'
|
45
|
+
|
46
|
+
Options:
|
47
|
+
EOB
|
48
|
+
parser.on("-n", "--preview", "Preview without executing commands") do |v|
|
49
|
+
opts[:preview] = v
|
50
|
+
end
|
51
|
+
|
52
|
+
parser.on("-p", "--project PATH", "Set project path") do |v|
|
53
|
+
opts[:project] = v
|
54
|
+
end
|
55
|
+
|
56
|
+
parser.on("-q", "--quiet", "Don't display commands executed") do |v|
|
57
|
+
opts[:verbosity] = Logger::ERROR
|
58
|
+
end
|
59
|
+
|
60
|
+
parser.on("-v", "--version", "Display version") do |v|
|
61
|
+
puts AutomateIt::VERSION
|
62
|
+
exit 0
|
63
|
+
end
|
64
|
+
|
65
|
+
parser.on("-h", "--help", "Display this help message") do |v|
|
66
|
+
puts parser
|
67
|
+
exit
|
68
|
+
end
|
69
|
+
|
70
|
+
args = parser.parse!.dup
|
71
|
+
query = args.shift
|
72
|
+
commands = args
|
73
|
+
|
74
|
+
if commands.blank?
|
75
|
+
puts parser
|
76
|
+
puts "\nERROR: No commands specified"
|
77
|
+
exit 1
|
78
|
+
end
|
79
|
+
|
80
|
+
interpreter = AutomateIt.new(
|
81
|
+
:project => opts[:project],
|
82
|
+
:verbosity => opts[:verbosity]
|
83
|
+
)
|
84
|
+
|
85
|
+
interpreter.preview true if opts[:preview]
|
86
|
+
|
87
|
+
for host in interpreter.hosts_tagged_with(query).sort
|
88
|
+
cmd = "ssh %s %s" % [host, commands.join(" ").shell_escape]
|
89
|
+
interpreter.sh(cmd)
|
90
|
+
end
|
91
|
+
|
92
|
+
exit 0
|
93
|
+
end
|
data/bin/aitag
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# XXX What can go wrong with this loading approach?
|
4
|
+
libdir = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
|
5
|
+
if File.directory?(libdir) and File.exists?(File.join(libdir, "automateit.rb"))
|
6
|
+
$LOAD_PATH.unshift(libdir)
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rubygems'
|
10
|
+
require 'optparse'
|
11
|
+
require 'automateit'
|
12
|
+
|
13
|
+
OptionParser.new do |parser|
|
14
|
+
PROG = File.basename($0)
|
15
|
+
opts = {}
|
16
|
+
parser.banner = <<EOB
|
17
|
+
#{PROG} - tool for querying AutomateIt tags
|
18
|
+
|
19
|
+
Usage: #{PROG} [options] [arguments...]
|
20
|
+
|
21
|
+
IMPORTANT:
|
22
|
+
#{PROG} can only match against tags specified in tags.yml. It cannot
|
23
|
+
match against automatically generated tags like the OS, architecture and such
|
24
|
+
which are created at runtime by PlatformManager or AddressManager. So if you
|
25
|
+
want to run a command against all Ubuntu servers, you must define them
|
26
|
+
explicitly in tags.yml.
|
27
|
+
|
28
|
+
Examples:
|
29
|
+
# Load 'myproject' and see if it's tagged with 'apache' or 'svn':
|
30
|
+
#{PROG} -p myproject 'apache || svn'
|
31
|
+
echo $?
|
32
|
+
|
33
|
+
# Same but using environmental variable to specify project:
|
34
|
+
AUTOMATEIT_PROJECT=myproject
|
35
|
+
#{PROG} 'apache || svn'
|
36
|
+
echo $?
|
37
|
+
|
38
|
+
# Dump the results of a query as YAML
|
39
|
+
#{PROG} -Y myapp#user
|
40
|
+
|
41
|
+
Options:
|
42
|
+
EOB
|
43
|
+
parser.on("-s", "--tags", "List tags for this host") do |v|
|
44
|
+
opts[:list_tags] = v
|
45
|
+
end
|
46
|
+
|
47
|
+
parser.on("-f", "--tags_for HOST", "List tags for a specific host") do |v|
|
48
|
+
opts[:tags_for] = v
|
49
|
+
end
|
50
|
+
|
51
|
+
parser.on("-t", "--tagged? QUERY", "Is this host tagged with the query?") do |v|
|
52
|
+
opts[:tagged?] = v
|
53
|
+
end
|
54
|
+
|
55
|
+
parser.on("-w", "--hosts_tagged_with QUERY", "List hosts tagged with query") do |v|
|
56
|
+
opts[:hosts_tagged_with] = v
|
57
|
+
end
|
58
|
+
|
59
|
+
parser.on("-p", "--project PATH", "Set project path") do |v|
|
60
|
+
opts[:project] = v
|
61
|
+
end
|
62
|
+
|
63
|
+
parser.on("-Y", "--yaml", "Dump as YAML") do |v|
|
64
|
+
opts[:yaml] = v
|
65
|
+
end
|
66
|
+
|
67
|
+
parser.on("-a", "--add TAGS", "Add list of space separated tags") do |v|
|
68
|
+
opts[:add_tags] = [v.split].flatten
|
69
|
+
end
|
70
|
+
|
71
|
+
parser.on("-v", "--version", "Display version") do |v|
|
72
|
+
puts AutomateIt::VERSION
|
73
|
+
exit 0
|
74
|
+
end
|
75
|
+
|
76
|
+
parser.on("-h", "--help", "Display this help message") do |v|
|
77
|
+
puts parser
|
78
|
+
exit
|
79
|
+
end
|
80
|
+
|
81
|
+
args = parser.parse!.dup
|
82
|
+
|
83
|
+
# Clear ARGV so that IRB doesn't try to parse our options
|
84
|
+
opts[:args] = args
|
85
|
+
ARGV.clear
|
86
|
+
|
87
|
+
interpreter = AutomateIt.new(
|
88
|
+
:project => opts[:project],
|
89
|
+
:tags => opts[:add_tags]
|
90
|
+
)
|
91
|
+
result = nil
|
92
|
+
|
93
|
+
unless opts[:list_tags] or opts[:tags_for] or opts[:tagged?] or opts[:hosts_tagged_with]
|
94
|
+
if args.first
|
95
|
+
opts[:tagged?] = args.first
|
96
|
+
else
|
97
|
+
puts parser
|
98
|
+
puts "\nERROR: insufficient arguments"
|
99
|
+
exit 1
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
result = \
|
104
|
+
if opts[:list_tags]
|
105
|
+
interpreter.tags.to_a.sort
|
106
|
+
elsif opts[:tags_for]
|
107
|
+
interpreter.tags_for(opts[:tags_for])
|
108
|
+
elsif opts[:tagged?]
|
109
|
+
exit(interpreter.tagged?(opts[:tagged?]) ? 0 : 1)
|
110
|
+
elsif opts[:hosts_tagged_with]
|
111
|
+
interpreter.hosts_tagged_with(opts[:hosts_tagged_with])
|
112
|
+
end
|
113
|
+
|
114
|
+
puts(
|
115
|
+
if result.nil?
|
116
|
+
result.inspect
|
117
|
+
elsif opts[:yaml]
|
118
|
+
result.to_yaml
|
119
|
+
else
|
120
|
+
case result
|
121
|
+
when String
|
122
|
+
result
|
123
|
+
when Set
|
124
|
+
result.sort.to_a.join(' ')
|
125
|
+
when Array
|
126
|
+
result.sort.join(' ')
|
127
|
+
else
|
128
|
+
result.inspect
|
129
|
+
end
|
130
|
+
end
|
131
|
+
)
|
132
|
+
|
133
|
+
exit 0
|
134
|
+
end
|
data/bin/automateit
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# XXX What can go wrong with this loading approach?
|
4
|
+
libdir = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
|
5
|
+
if File.directory?(libdir) and File.exists?(File.join(libdir, "automateit.rb"))
|
6
|
+
$LOAD_PATH.unshift(libdir)
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rubygems'
|
10
|
+
require 'logger'
|
11
|
+
require 'optparse'
|
12
|
+
require 'automateit'
|
13
|
+
|
14
|
+
include AutomateIt::Constants
|
15
|
+
|
16
|
+
OptionParser.new do |parser|
|
17
|
+
PROG = File.basename($0)
|
18
|
+
opts = {}
|
19
|
+
parser.banner = <<EOB
|
20
|
+
#{PROG} - tool for automating the setup and maintenance of servers
|
21
|
+
|
22
|
+
Usage: #{PROG} [options] [recipe]
|
23
|
+
|
24
|
+
Examples:
|
25
|
+
# Start an interactive shell session
|
26
|
+
#{PROG}
|
27
|
+
|
28
|
+
# Execute a recipe
|
29
|
+
#{PROG} myrecipe.rb
|
30
|
+
|
31
|
+
# Preview the commands a recipe will run without running them
|
32
|
+
#{PROG} -n myrecipe.rb
|
33
|
+
|
34
|
+
# Eval a string
|
35
|
+
#{PROG} -e "puts tags.to_a.inspect"
|
36
|
+
|
37
|
+
# Add a tag
|
38
|
+
#{PROG} -a mytag -e "puts tags.to_a.inspect"
|
39
|
+
|
40
|
+
# Add tags
|
41
|
+
#{PROG} -a 'mytag othertag' -e "puts tags.to_a.inspect"
|
42
|
+
|
43
|
+
Options:
|
44
|
+
EOB
|
45
|
+
parser.on("-c", "--create PATH", "Create project at path") do |v|
|
46
|
+
opts[:create] = v
|
47
|
+
end
|
48
|
+
|
49
|
+
parser.on("-p", "--project PATH", "Set project path") do |v|
|
50
|
+
opts[:project] = v
|
51
|
+
end
|
52
|
+
|
53
|
+
parser.on("-n", "--preview", "Preview without executing commands") do |v|
|
54
|
+
opts[:preview] = v
|
55
|
+
end
|
56
|
+
|
57
|
+
parser.on("-e", "--eval STRING", "Evaluate string") do |v|
|
58
|
+
opts[:eval] = v
|
59
|
+
end
|
60
|
+
|
61
|
+
parser.on("-a", "--add TAGS", "Add list of space separated tags") do |v|
|
62
|
+
opts[:tags] = [v.split].flatten
|
63
|
+
end
|
64
|
+
|
65
|
+
parser.on("-q", "--quiet", "Print only errors") do |v|
|
66
|
+
opts[:verbosity] = Logger::ERROR
|
67
|
+
end
|
68
|
+
|
69
|
+
parser.on("-d", "--debug", "Print debugging information") do |v|
|
70
|
+
opts[:verbosity] = Logger::DEBUG
|
71
|
+
end
|
72
|
+
|
73
|
+
parser.on("-T", "--trace", "Display raw exception traces") do |v|
|
74
|
+
opts[:friendly_exceptions] = ! v
|
75
|
+
end
|
76
|
+
|
77
|
+
parser.on("-v", "--version", "Display version") do |v|
|
78
|
+
puts AutomateIt::VERSION
|
79
|
+
exit 0
|
80
|
+
end
|
81
|
+
|
82
|
+
parser.on("-h", "--help", "Display this help message") do |v|
|
83
|
+
puts parser
|
84
|
+
exit
|
85
|
+
end
|
86
|
+
|
87
|
+
args = parser.parse!.dup
|
88
|
+
|
89
|
+
# Clear ARGV so that IRB doesn't try to parse our options
|
90
|
+
opts[:args] = args
|
91
|
+
ARGV.clear
|
92
|
+
|
93
|
+
opts[:recipe] = args.first unless args.empty?
|
94
|
+
|
95
|
+
# Save vars because +run+ will delete opts
|
96
|
+
argscopy = args.clone
|
97
|
+
optscopy = opts.clone
|
98
|
+
|
99
|
+
# Display newline at the end
|
100
|
+
newline = true
|
101
|
+
|
102
|
+
begin
|
103
|
+
rv = AutomateIt::CLI.run(opts)
|
104
|
+
rescue SystemExit
|
105
|
+
# Don't display errors when 'exit' is run
|
106
|
+
newline = false
|
107
|
+
rescue Exception => e
|
108
|
+
msg = nil
|
109
|
+
if e.is_a?(AutomateIt::Error) and e.cause.to_s =~ /IRB_EXIT/
|
110
|
+
# Don't display errors interpreter is closed with 'CTRL-D'
|
111
|
+
elsif opts[:friendly_exceptions] != false and e.is_a?(AutomateIt::Error)
|
112
|
+
# Friendly message
|
113
|
+
msg = PERROR+e.message
|
114
|
+
msg << "\n\n"+PNOTE+"Use 'automateit --trace' to see complete backtrace"
|
115
|
+
else
|
116
|
+
# Raw backtrace
|
117
|
+
puts PERROR+"AutomateIt error trace:"
|
118
|
+
stack = e.backtrace.clone
|
119
|
+
msg = "#{stack.shift}: #{e.message} (#{e.exception.class})}";
|
120
|
+
for line in stack
|
121
|
+
msg << "\n "+line
|
122
|
+
end
|
123
|
+
end
|
124
|
+
puts msg
|
125
|
+
exit 1
|
126
|
+
end
|
127
|
+
if optscopy[:create] or optscopy[:eval] or argscopy.size > 0
|
128
|
+
exit rv ? 0 :1
|
129
|
+
elsif newline
|
130
|
+
# CTRL-D ends the line prematurely, so add a newline
|
131
|
+
puts
|
132
|
+
end
|
133
|
+
end
|