mamertes 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.DS_Store +0 -0
- data/.gitignore +6 -0
- data/.travis-gemfile +15 -0
- data/.travis.yml +10 -0
- data/.yardopts +1 -0
- data/Gemfile +21 -0
- data/README.md +126 -0
- data/Rakefile +29 -0
- data/doc/Mamertes.html +155 -0
- data/doc/Mamertes/Application.html +3057 -0
- data/doc/Mamertes/Command.html +7031 -0
- data/doc/Mamertes/CommandMethods.html +125 -0
- data/doc/Mamertes/CommandMethods/Children.html +1286 -0
- data/doc/Mamertes/CommandMethods/Help.html +209 -0
- data/doc/Mamertes/Error.html +631 -0
- data/doc/Mamertes/Localizer.html +376 -0
- data/doc/Mamertes/Option.html +6671 -0
- data/doc/Mamertes/Parser.html +276 -0
- data/doc/Mamertes/ParserMethods.html +125 -0
- data/doc/Mamertes/ParserMethods/General.html +134 -0
- data/doc/Mamertes/ParserMethods/General/ClassMethods.html +574 -0
- data/doc/Mamertes/Version.html +189 -0
- data/doc/_index.html +276 -0
- data/doc/class_list.html +54 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +338 -0
- data/doc/file.README.html +198 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +28 -0
- data/doc/index.html +198 -0
- data/doc/js/app.js +214 -0
- data/doc/js/full_list.js +178 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +509 -0
- data/doc/top-level-namespace.html +112 -0
- data/lib/mamertes.rb +18 -0
- data/lib/mamertes/application.rb +206 -0
- data/lib/mamertes/command.rb +529 -0
- data/lib/mamertes/option.rb +236 -0
- data/lib/mamertes/parser.rb +317 -0
- data/lib/mamertes/version.rb +24 -0
- data/locales/en.yml +40 -0
- data/locales/it.yml +40 -0
- data/mamertes.gemspec +30 -0
- data/spec/coverage_helper.rb +20 -0
- data/spec/mamertes/application_spec.rb +181 -0
- data/spec/mamertes/command_spec.rb +526 -0
- data/spec/mamertes/option_spec.rb +274 -0
- data/spec/mamertes/parser_spec.rb +126 -0
- data/spec/spec_helper.rb +15 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTA0NzI4YzEwMGFmZmJiMjBmZjI4MzQwYzQwOTAxZWQzM2MxZGQzNA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NWZkNTEyY2ZmMjQyMTY1ZTAxMGZlNjFmZjE4NzY0YjgyZDI0NGYzZA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MzY0MTUxMmQxOTU1NDYzZTg0NzUyNjU0ZmEwZGNmYTVjYzRjZGZiZGRjNmU5
|
10
|
+
NDNiNGFhNDcwNmVhYzZjNGNiZTY2MzNkZWU0YzIxMDMyZmM1NjRkZDcyYzgz
|
11
|
+
NjUwODAwNWVlOWE2MzM2YmUwYTBkYzcwMDEwYWU4NGUzNTI2Mjk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OTRjMGFkNmJkZWYwYmI0YzAwYWJhNTkzYjM3NzE1ZDkyMWZkNTg0Yzg0NzA0
|
14
|
+
M2E1MGFjNzRmNTA0NjEzMTZjMWE0ZWFjMWU5Y2FjMjhhMmU4MGFmYzlkM2Fm
|
15
|
+
MGQxNzVjNDI5N2I4MDNiZTdiMGVjZmI4Njg5ZjU1YTg1MDRlMTU=
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.travis-gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# This file is part of the mamertes gem. Copyright (C) 2013 and above Shogun <shogun_panda@me.com>.
|
4
|
+
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
5
|
+
#
|
6
|
+
|
7
|
+
source "http://rubygems.org"
|
8
|
+
|
9
|
+
gemspec
|
10
|
+
|
11
|
+
# Testing
|
12
|
+
gem "rspec", "~> 2.14.1"
|
13
|
+
gem "rake", "~> 10.1.0"
|
14
|
+
gem "simplecov", ">= 0.7.1"
|
15
|
+
gem "coveralls", ">= 0.6.7", require: false
|
data/.travis.yml
ADDED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-m markdown
|
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# This file is part of the mamertes gem. Copyright (C) 2013 and above Shogun <shogun_panda@me.com>.
|
4
|
+
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
5
|
+
#
|
6
|
+
|
7
|
+
source "http://rubygems.org"
|
8
|
+
|
9
|
+
gemspec
|
10
|
+
|
11
|
+
# Testing
|
12
|
+
gem "rspec", "~> 2.14.1"
|
13
|
+
gem "rake", "~> 10.1.0"
|
14
|
+
|
15
|
+
# Documentation
|
16
|
+
gem "simplecov", ">= 0.7.1"
|
17
|
+
gem "coveralls", ">= 0.6.7", require: false
|
18
|
+
gem "pry", ">= 0"
|
19
|
+
gem "yard", ">= 0.8.6"
|
20
|
+
gem "kramdown", ">= 1.1.0"
|
21
|
+
gem "github-markup", ">= 0.7.5"
|
data/README.md
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
# mamertes
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/mamertes.png)](http://badge.fury.io/rb/mamertes)
|
4
|
+
[![Dependency Status](https://gemnasium.com/ShogunPanda/mamertes.png?travis)](https://gemnasium.com/ShogunPanda/mamertes)
|
5
|
+
[![Build Status](https://secure.travis-ci.org/ShogunPanda/mamertes.png?branch=master)](http://travis-ci.org/ShogunPanda/mamertes)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/ShogunPanda/mamertes.png)](https://codeclimate.com/github/ShogunPanda/mamertes)
|
7
|
+
[![Coverage Status](https://coveralls.io/repos/ShogunPanda/mamertes/badge.png)](https://coveralls.io/r/ShogunPanda/mamertes)
|
8
|
+
|
9
|
+
Yet another command line manager.
|
10
|
+
|
11
|
+
http://sw.cow.tc/mamertes
|
12
|
+
|
13
|
+
http://rdoc.info/gems/mamertes
|
14
|
+
|
15
|
+
## Basic usage.
|
16
|
+
|
17
|
+
As ever, talking by example is always better.
|
18
|
+
This application:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
require "rubygems"
|
22
|
+
require "mamertes"
|
23
|
+
|
24
|
+
Mamertes::Application.create(name: "Mamertes Usage Test", version: "1.0.0", description: "An example modelled like a TODO application", banner: "Do you like Mamertes?") do
|
25
|
+
option(:storage, ["f", "file"], {type: String, help: "The file where store TODOs to.", meta: "FILE"})
|
26
|
+
|
27
|
+
command :list do
|
28
|
+
description "List all TODOs."
|
29
|
+
action do |command|
|
30
|
+
# You should implement this.
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
command :manage, {description: "Manage existing TODO."} do
|
35
|
+
option(:verbose, [], {help: "Be verbose."})
|
36
|
+
|
37
|
+
action do |command|
|
38
|
+
puts "Please use \"add\" or \"remove\" subcommands."
|
39
|
+
end
|
40
|
+
|
41
|
+
command :add, {description: "Add a TODO."} do
|
42
|
+
action do |command|
|
43
|
+
# You should implement this.
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
command :remove, {description: "Removes a TODO."} do
|
48
|
+
action do |command|
|
49
|
+
# You should implement this.
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
Will create a complete (at least at the interface model) TODO application which support commands `list` and `manage`.
|
57
|
+
|
58
|
+
The `manage` command supports subcommands `add` and `remove`. You can invoke it via syntax `manage add` or `manage:add`. **If there is no conflict, just `m:r` is sufficient!**
|
59
|
+
|
60
|
+
To provide (sub)commands, both hash-style or block-style method style are supported (except for the `action` option), as you can see in the example.
|
61
|
+
|
62
|
+
You can use the `--help` switch or the `help command` syntax to navigate through commands details.
|
63
|
+
|
64
|
+
After setting up the skeleton, you will just need to write the action bodies and you're done. **Happy coding!**
|
65
|
+
|
66
|
+
### Wrapping up the example
|
67
|
+
Here's the help screen of the application above for the global application and for the `manage` command.
|
68
|
+
|
69
|
+
#### General help
|
70
|
+
|
71
|
+
```
|
72
|
+
$ ./test -h
|
73
|
+
[NAME]
|
74
|
+
Mamertes Usage Test 1.0.0 - An example modelled like a TODO application
|
75
|
+
|
76
|
+
[SYNOPSIS]
|
77
|
+
test [options] [command [subcommand ...]][command-options] [arguments]
|
78
|
+
|
79
|
+
[DESCRIPTION]
|
80
|
+
Do you like Mamertes?
|
81
|
+
|
82
|
+
[GLOBAL OPTIONS]
|
83
|
+
-f FILE, --file FILE - The file where store TODOs to.
|
84
|
+
-h, --help - Shows this message.
|
85
|
+
|
86
|
+
[COMMANDS]
|
87
|
+
help - Shows a help about a command.
|
88
|
+
list - List all TODOs.
|
89
|
+
manage - Manage existing TODO.
|
90
|
+
```
|
91
|
+
|
92
|
+
#### The `manage` command help
|
93
|
+
|
94
|
+
```
|
95
|
+
$ ./test help manage
|
96
|
+
[SYNOPSIS]
|
97
|
+
test [options] manage [subcommand ...]] [command-options] [arguments]
|
98
|
+
|
99
|
+
[OPTIONS]
|
100
|
+
-v, --verbose - Be verbose.
|
101
|
+
|
102
|
+
[SUBCOMMANDS]
|
103
|
+
add - Add a TODO.
|
104
|
+
remove - Removes a TODO.
|
105
|
+
```
|
106
|
+
|
107
|
+
|
108
|
+
## Advanced usage
|
109
|
+
|
110
|
+
See documentation for more information.
|
111
|
+
|
112
|
+
## Contributing to mamertes
|
113
|
+
|
114
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
115
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
116
|
+
* Fork the project.
|
117
|
+
* Start a feature/bugfix branch.
|
118
|
+
* Commit and push until you are happy with your contribution.
|
119
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
120
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
121
|
+
|
122
|
+
## Copyright
|
123
|
+
|
124
|
+
Copyright (C) 2013 and above Shogun (shogun_panda@me.com).
|
125
|
+
|
126
|
+
Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php).
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# This file is part of the mamertes gem. Copyright (C) 2011 and above Shogun <shogun_panda@me.com>.
|
4
|
+
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
5
|
+
#
|
6
|
+
|
7
|
+
require "bundler/gem_tasks"
|
8
|
+
require "rspec/core/rake_task"
|
9
|
+
|
10
|
+
RSpec::Core::RakeTask.new("spec")
|
11
|
+
RSpec::Core::RakeTask.new("spec:coverage") { |t| t.ruby_opts = "-r./spec/coverage_helper" }
|
12
|
+
|
13
|
+
desc "Generate the documentation"
|
14
|
+
task :docs do
|
15
|
+
system("yardoc") || raise("Failed Execution of: yardoc")
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Get the current release version"
|
19
|
+
task :version, :with_name do |_, args|
|
20
|
+
gem = Bundler::GemHelper.instance.gemspec
|
21
|
+
puts [args[:with_name] == "true" ? gem.name : nil, gem.version].compact.join("-")
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Prepare the release"
|
25
|
+
task :prerelease => ["spec:coverage", "docs"] do
|
26
|
+
["git add -A", "git commit -am \"Version #{Bundler::GemHelper.instance.gemspec.version}\""].each do |cmd|
|
27
|
+
system(cmd) || raise("Failed Execution of: #{cmd}")
|
28
|
+
end
|
29
|
+
end
|
data/doc/Mamertes.html
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>
|
7
|
+
Module: Mamertes
|
8
|
+
|
9
|
+
— Documentation by YARD 0.8.6.2
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
19
|
+
relpath = '';
|
20
|
+
framesUrl = "frames.html#!" + escape(window.location.href);
|
21
|
+
</script>
|
22
|
+
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
25
|
+
|
26
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
27
|
+
|
28
|
+
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="header">
|
32
|
+
<div id="menu">
|
33
|
+
|
34
|
+
<a href="_index.html">Index (M)</a> »
|
35
|
+
|
36
|
+
|
37
|
+
<span class="title">Mamertes</span>
|
38
|
+
|
39
|
+
|
40
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
<div id="search">
|
44
|
+
|
45
|
+
<a class="full_list_link" id="class_list_link"
|
46
|
+
href="class_list.html">
|
47
|
+
Class List
|
48
|
+
</a>
|
49
|
+
|
50
|
+
<a class="full_list_link" id="method_list_link"
|
51
|
+
href="method_list.html">
|
52
|
+
Method List
|
53
|
+
</a>
|
54
|
+
|
55
|
+
<a class="full_list_link" id="file_list_link"
|
56
|
+
href="file_list.html">
|
57
|
+
File List
|
58
|
+
</a>
|
59
|
+
|
60
|
+
</div>
|
61
|
+
<div class="clear"></div>
|
62
|
+
</div>
|
63
|
+
|
64
|
+
<iframe id="search_frame"></iframe>
|
65
|
+
|
66
|
+
<div id="content"><h1>Module: Mamertes
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
</h1>
|
71
|
+
|
72
|
+
<dl class="box">
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
<dt class="r1 last">Defined in:</dt>
|
82
|
+
<dd class="r1 last">lib/mamertes/option.rb<span class="defines">,<br />
|
83
|
+
lib/mamertes/parser.rb,<br /> lib/mamertes/command.rb,<br /> lib/mamertes/version.rb,<br /> lib/mamertes/application.rb</span>
|
84
|
+
</dd>
|
85
|
+
|
86
|
+
</dl>
|
87
|
+
<div class="clear"></div>
|
88
|
+
|
89
|
+
<h2>Overview</h2><div class="docstring">
|
90
|
+
<div class="discussion">
|
91
|
+
<p>Yet another command line manager.</p>
|
92
|
+
|
93
|
+
|
94
|
+
</div>
|
95
|
+
</div>
|
96
|
+
<div class="tags">
|
97
|
+
|
98
|
+
|
99
|
+
</div><h2>Defined Under Namespace</h2>
|
100
|
+
<p class="children">
|
101
|
+
|
102
|
+
|
103
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Mamertes/CommandMethods.html" title="Mamertes::CommandMethods (module)">CommandMethods</a></span>, <span class='object_link'><a href="Mamertes/ParserMethods.html" title="Mamertes::ParserMethods (module)">ParserMethods</a></span>, <span class='object_link'><a href="Mamertes/Version.html" title="Mamertes::Version (module)">Version</a></span>
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Mamertes/Application.html" title="Mamertes::Application (class)">Application</a></span>, <span class='object_link'><a href="Mamertes/Command.html" title="Mamertes::Command (class)">Command</a></span>, <span class='object_link'><a href="Mamertes/Error.html" title="Mamertes::Error (class)">Error</a></span>, <span class='object_link'><a href="Mamertes/Localizer.html" title="Mamertes::Localizer (class)">Localizer</a></span>, <span class='object_link'><a href="Mamertes/Option.html" title="Mamertes::Option (class)">Option</a></span>, <span class='object_link'><a href="Mamertes/Parser.html" title="Mamertes::Parser (class)">Parser</a></span>
|
108
|
+
|
109
|
+
|
110
|
+
</p>
|
111
|
+
|
112
|
+
<h2>Constant Summary</h2>
|
113
|
+
|
114
|
+
<dl class="constants">
|
115
|
+
|
116
|
+
<dt id="OPTION_TYPES-constant" class="">OPTION_TYPES =
|
117
|
+
<div class="docstring">
|
118
|
+
<div class="discussion">
|
119
|
+
<p>List of valid option types.</p>
|
120
|
+
|
121
|
+
<p>Values are the default values for that type.</p>
|
122
|
+
|
123
|
+
<p>For any unknown type, the default value is <code>false</code>, it means that any unknown type is managed as a Boolean value with no argument.</p>
|
124
|
+
|
125
|
+
|
126
|
+
</div>
|
127
|
+
</div>
|
128
|
+
<div class="tags">
|
129
|
+
|
130
|
+
|
131
|
+
</div>
|
132
|
+
</dt>
|
133
|
+
<dd><pre class="code"><span class='lbrace'>{</span><span class='const'>String</span> <span class='op'>=></span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='const'>Integer</span> <span class='op'>=></span> <span class='int'>0</span><span class='comma'>,</span> <span class='const'>Float</span> <span class='op'>=></span> <span class='float'>0.0</span><span class='comma'>,</span> <span class='const'>Array</span> <span class='op'>=></span> <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rbrace'>}</span></pre></dd>
|
134
|
+
|
135
|
+
</dl>
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
</div>
|
147
|
+
|
148
|
+
<div id="footer">
|
149
|
+
Generated on Sat Aug 10 16:23:08 2013 by
|
150
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
151
|
+
0.8.6.2 (ruby-1.9.3).
|
152
|
+
</div>
|
153
|
+
|
154
|
+
</body>
|
155
|
+
</html>
|
@@ -0,0 +1,3057 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>
|
7
|
+
Class: Mamertes::Application
|
8
|
+
|
9
|
+
— Documentation by YARD 0.8.6.2
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
19
|
+
relpath = '../';
|
20
|
+
framesUrl = "../frames.html#!" + escape(window.location.href);
|
21
|
+
</script>
|
22
|
+
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
|
25
|
+
|
26
|
+
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
|
27
|
+
|
28
|
+
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="header">
|
32
|
+
<div id="menu">
|
33
|
+
|
34
|
+
<a href="../_index.html">Index (A)</a> »
|
35
|
+
<span class='title'><span class='object_link'><a href="../Mamertes.html" title="Mamertes (module)">Mamertes</a></span></span>
|
36
|
+
»
|
37
|
+
<span class="title">Application</span>
|
38
|
+
|
39
|
+
|
40
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
<div id="search">
|
44
|
+
|
45
|
+
<a class="full_list_link" id="class_list_link"
|
46
|
+
href="../class_list.html">
|
47
|
+
Class List
|
48
|
+
</a>
|
49
|
+
|
50
|
+
<a class="full_list_link" id="method_list_link"
|
51
|
+
href="../method_list.html">
|
52
|
+
Method List
|
53
|
+
</a>
|
54
|
+
|
55
|
+
<a class="full_list_link" id="file_list_link"
|
56
|
+
href="../file_list.html">
|
57
|
+
File List
|
58
|
+
</a>
|
59
|
+
|
60
|
+
</div>
|
61
|
+
<div class="clear"></div>
|
62
|
+
</div>
|
63
|
+
|
64
|
+
<iframe id="search_frame"></iframe>
|
65
|
+
|
66
|
+
<div id="content"><h1>Class: Mamertes::Application
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
</h1>
|
71
|
+
|
72
|
+
<dl class="box">
|
73
|
+
|
74
|
+
<dt class="r1">Inherits:</dt>
|
75
|
+
<dd class="r1">
|
76
|
+
<span class="inheritName"><span class='object_link'><a href="Command.html" title="Mamertes::Command (class)">Command</a></span></span>
|
77
|
+
|
78
|
+
<ul class="fullTree">
|
79
|
+
<li>Object</li>
|
80
|
+
|
81
|
+
<li class="next"><span class='object_link'><a href="Command.html" title="Mamertes::Command (class)">Command</a></span></li>
|
82
|
+
|
83
|
+
<li class="next">Mamertes::Application</li>
|
84
|
+
|
85
|
+
</ul>
|
86
|
+
<a href="#" class="inheritanceTree">show all</a>
|
87
|
+
|
88
|
+
</dd>
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
<dt class="r2 last">Defined in:</dt>
|
99
|
+
<dd class="r2 last">lib/mamertes/application.rb</dd>
|
100
|
+
|
101
|
+
</dl>
|
102
|
+
<div class="clear"></div>
|
103
|
+
|
104
|
+
<h2>Overview</h2><div class="docstring">
|
105
|
+
<div class="discussion">
|
106
|
+
<p>This is the main class for a Mamertes application.</p>
|
107
|
+
|
108
|
+
<p>Basically is the same of a command, but it adds support for application version.</p>
|
109
|
+
|
110
|
+
|
111
|
+
</div>
|
112
|
+
</div>
|
113
|
+
<div class="tags">
|
114
|
+
|
115
|
+
|
116
|
+
</div>
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
<h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
|
121
|
+
<ul class="summary">
|
122
|
+
|
123
|
+
<li class="public ">
|
124
|
+
<span class="summary_signature">
|
125
|
+
|
126
|
+
<a href="#console-instance_method" title="#console (instance method)">- (::Bovem::Console) <strong>console</strong> </a>
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
</span>
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
<span class="summary_desc"><div class='inline'><p>A console helper.</p>
|
144
|
+
</div></span>
|
145
|
+
|
146
|
+
</li>
|
147
|
+
|
148
|
+
|
149
|
+
<li class="public ">
|
150
|
+
<span class="summary_signature">
|
151
|
+
|
152
|
+
<a href="#output_commands-instance_method" title="#output_commands (instance method)">- (Boolean) <strong>output_commands</strong> </a>
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
</span>
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
<span class="summary_desc"><div class='inline'><p>If to show the output of the commands run via <span class='object_link'><a href="#run-instance_method" title="Mamertes::Application#run (method)">#run</a></span>.</p>
|
170
|
+
</div></span>
|
171
|
+
|
172
|
+
</li>
|
173
|
+
|
174
|
+
|
175
|
+
<li class="public ">
|
176
|
+
<span class="summary_signature">
|
177
|
+
|
178
|
+
<a href="#shell-instance_method" title="#shell (instance method)">- (::Bovem::Shell) <strong>shell</strong> </a>
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
</span>
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
<span class="summary_desc"><div class='inline'><p>A shell helper.</p>
|
196
|
+
</div></span>
|
197
|
+
|
198
|
+
</li>
|
199
|
+
|
200
|
+
|
201
|
+
<li class="public ">
|
202
|
+
<span class="summary_signature">
|
203
|
+
|
204
|
+
<a href="#show_commands-instance_method" title="#show_commands (instance method)">- (Boolean) <strong>show_commands</strong> </a>
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
</span>
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
<span class="summary_desc"><div class='inline'><p>If to show command lines run via <span class='object_link'><a href="#run-instance_method" title="Mamertes::Application#run (method)">#run</a></span>.</p>
|
222
|
+
</div></span>
|
223
|
+
|
224
|
+
</li>
|
225
|
+
|
226
|
+
|
227
|
+
<li class="public ">
|
228
|
+
<span class="summary_signature">
|
229
|
+
|
230
|
+
<a href="#skip_commands-instance_method" title="#skip_commands (instance method)">- (Boolean) <strong>skip_commands</strong> </a>
|
231
|
+
|
232
|
+
|
233
|
+
|
234
|
+
</span>
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
<span class="summary_desc"><div class='inline'><p>If to skip commands run via <span class='object_link'><a href="#run-instance_method" title="Mamertes::Application#run (method)">#run</a></span>.</p>
|
248
|
+
</div></span>
|
249
|
+
|
250
|
+
</li>
|
251
|
+
|
252
|
+
|
253
|
+
<li class="public ">
|
254
|
+
<span class="summary_signature">
|
255
|
+
|
256
|
+
<a href="#version-instance_method" title="#version (instance method)">- (String|nil) <strong>version</strong>(value = nil) </a>
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
</span>
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
<span class="summary_desc"><div class='inline'><p>Reads and optionally sets the version of this application.</p>
|
274
|
+
</div></span>
|
275
|
+
|
276
|
+
</li>
|
277
|
+
|
278
|
+
|
279
|
+
</ul>
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
<h3 class="inherited">Attributes inherited from <span class='object_link'><a href="Command.html" title="Mamertes::Command (class)">Command</a></span></h3>
|
286
|
+
<p class="inherited"><span class='object_link'><a href="Command.html#action-instance_method" title="Mamertes::Command#action (method)">#action</a></span>, <span class='object_link'><a href="Command.html#after-instance_method" title="Mamertes::Command#after (method)">#after</a></span>, <span class='object_link'><a href="Command.html#application-instance_method" title="Mamertes::Command#application (method)">#application</a></span>, <span class='object_link'><a href="Command.html#arguments-instance_method" title="Mamertes::Command#arguments (method)">#arguments</a></span>, <span class='object_link'><a href="Command.html#banner-instance_method" title="Mamertes::Command#banner (method)">#banner</a></span>, <span class='object_link'><a href="Command.html#before-instance_method" title="Mamertes::Command#before (method)">#before</a></span>, <span class='object_link'><a href="Command.html#commands-instance_method" title="Mamertes::Command#commands (method)">#commands</a></span>, <span class='object_link'><a href="Command.html#description-instance_method" title="Mamertes::Command#description (method)">#description</a></span>, <span class='object_link'><a href="Command.html#name-instance_method" title="Mamertes::Command#name (method)">#name</a></span>, <span class='object_link'><a href="Command.html#options-instance_method" title="Mamertes::Command#options (method)">#options</a></span>, <span class='object_link'><a href="Command.html#parent-instance_method" title="Mamertes::Command#parent (method)">#parent</a></span>, <span class='object_link'><a href="Command.html#synopsis-instance_method" title="Mamertes::Command#synopsis (method)">#synopsis</a></span></p>
|
287
|
+
|
288
|
+
|
289
|
+
|
290
|
+
<h3 class="inherited">Attributes included from <span class='object_link'><a href="CommandMethods/Children.html" title="Mamertes::CommandMethods::Children (module)">CommandMethods::Children</a></span></h3>
|
291
|
+
<p class="inherited"><span class='object_link'><a href="CommandMethods/Children.html#commands-instance_method" title="Mamertes::CommandMethods::Children#commands (method)">#commands</a></span>, <span class='object_link'><a href="CommandMethods/Children.html#options-instance_method" title="Mamertes::CommandMethods::Children#options (method)">#options</a></span></p>
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
<h2>
|
296
|
+
Class Method Summary
|
297
|
+
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
|
298
|
+
</h2>
|
299
|
+
|
300
|
+
<ul class="summary">
|
301
|
+
|
302
|
+
<li class="public ">
|
303
|
+
<span class="summary_signature">
|
304
|
+
|
305
|
+
<a href="#create-class_method" title="create (class method)">+ (Application) <strong>create</strong>(options = {}, &block) </a>
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
</span>
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
<span class="summary_desc"><div class='inline'><p>Initializes a new Mamertes application.</p>
|
320
|
+
</div></span>
|
321
|
+
|
322
|
+
</li>
|
323
|
+
|
324
|
+
|
325
|
+
</ul>
|
326
|
+
|
327
|
+
<h2>
|
328
|
+
Instance Method Summary
|
329
|
+
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
|
330
|
+
</h2>
|
331
|
+
|
332
|
+
<ul class="summary">
|
333
|
+
|
334
|
+
<li class="public ">
|
335
|
+
<span class="summary_signature">
|
336
|
+
|
337
|
+
<a href="#command_help-instance_method" title="#command_help (instance method)">- (Object) <strong>command_help</strong>(command) </a>
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
</span>
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
<span class="summary_desc"><div class='inline'><p>Shows a help about a command.</p>
|
352
|
+
</div></span>
|
353
|
+
|
354
|
+
</li>
|
355
|
+
|
356
|
+
|
357
|
+
<li class="public ">
|
358
|
+
<span class="summary_signature">
|
359
|
+
|
360
|
+
<a href="#executable_name-instance_method" title="#executable_name (instance method)">- (String) <strong>executable_name</strong> </a>
|
361
|
+
|
362
|
+
|
363
|
+
|
364
|
+
</span>
|
365
|
+
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
|
374
|
+
<span class="summary_desc"><div class='inline'><p>The name of the current executable.</p>
|
375
|
+
</div></span>
|
376
|
+
|
377
|
+
</li>
|
378
|
+
|
379
|
+
|
380
|
+
<li class="public ">
|
381
|
+
<span class="summary_signature">
|
382
|
+
|
383
|
+
<a href="#execute-instance_method" title="#execute (instance method)">- (Object) <strong>execute</strong>(args = nil) </a>
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
</span>
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
<span class="summary_desc"><div class='inline'><p>Executes this application.</p>
|
398
|
+
</div></span>
|
399
|
+
|
400
|
+
</li>
|
401
|
+
|
402
|
+
|
403
|
+
<li class="public ">
|
404
|
+
<span class="summary_signature">
|
405
|
+
|
406
|
+
<a href="#help_option-instance_method" title="#help_option (instance method)">- (Object) <strong>help_option</strong> </a>
|
407
|
+
|
408
|
+
|
409
|
+
|
410
|
+
</span>
|
411
|
+
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
|
420
|
+
<span class="summary_desc"><div class='inline'><p>Adds a help command and a help option to this application.</p>
|
421
|
+
</div></span>
|
422
|
+
|
423
|
+
</li>
|
424
|
+
|
425
|
+
|
426
|
+
<li class="public ">
|
427
|
+
<span class="summary_signature">
|
428
|
+
|
429
|
+
<a href="#initialize-instance_method" title="#initialize (instance method)">- (Application) <strong>initialize</strong>(options = {}, &block) </a>
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
</span>
|
434
|
+
|
435
|
+
|
436
|
+
<span class="note title constructor">constructor</span>
|
437
|
+
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
<span class="summary_desc"><div class='inline'><p>Creates a new application.</p>
|
446
|
+
</div></span>
|
447
|
+
|
448
|
+
</li>
|
449
|
+
|
450
|
+
|
451
|
+
<li class="public ">
|
452
|
+
<span class="summary_signature">
|
453
|
+
|
454
|
+
<a href="#run-instance_method" title="#run (instance method)">- (Hash) <strong>run</strong>(command, message = nil, show_exit = true, fatal = true) </a>
|
455
|
+
|
456
|
+
|
457
|
+
|
458
|
+
</span>
|
459
|
+
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
|
468
|
+
<span class="summary_desc"><div class='inline'><p>Runs a command into the shell.</p>
|
469
|
+
</div></span>
|
470
|
+
|
471
|
+
</li>
|
472
|
+
|
473
|
+
|
474
|
+
</ul>
|
475
|
+
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
|
486
|
+
<h3 class="inherited">Methods inherited from <span class='object_link'><a href="Command.html" title="Mamertes::Command (class)">Command</a></span></h3>
|
487
|
+
<p class="inherited"><span class='object_link'><a href="Command.html#full_name-instance_method" title="Mamertes::Command#full_name (method)">#full_name</a></span>, <span class='object_link'><a href="Command.html#has_banner%3F-instance_method" title="Mamertes::Command#has_banner? (method)">#has_banner?</a></span>, <span class='object_link'><a href="Command.html#has_description%3F-instance_method" title="Mamertes::Command#has_description? (method)">#has_description?</a></span>, <span class='object_link'><a href="Command.html#is_application%3F-instance_method" title="Mamertes::Command#is_application? (method)">#is_application?</a></span>, <span class='object_link'><a href="Command.html#setup_with-instance_method" title="Mamertes::Command#setup_with (method)">#setup_with</a></span></p>
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
<h3 class="inherited">Methods included from <span class='object_link'><a href="CommandMethods/Children.html" title="Mamertes::CommandMethods::Children (module)">CommandMethods::Children</a></span></h3>
|
498
|
+
<p class="inherited"><span class='object_link'><a href="CommandMethods/Children.html#argument-instance_method" title="Mamertes::CommandMethods::Children#argument (method)">#argument</a></span>, <span class='object_link'><a href="CommandMethods/Children.html#arguments-instance_method" title="Mamertes::CommandMethods::Children#arguments (method)">#arguments</a></span>, <span class='object_link'><a href="CommandMethods/Children.html#clear_commands-instance_method" title="Mamertes::CommandMethods::Children#clear_commands (method)">#clear_commands</a></span>, <span class='object_link'><a href="CommandMethods/Children.html#clear_options-instance_method" title="Mamertes::CommandMethods::Children#clear_options (method)">#clear_options</a></span>, <span class='object_link'><a href="CommandMethods/Children.html#command-instance_method" title="Mamertes::CommandMethods::Children#command (method)">#command</a></span>, <span class='object_link'><a href="CommandMethods/Children.html#get_options-instance_method" title="Mamertes::CommandMethods::Children#get_options (method)">#get_options</a></span>, <span class='object_link'><a href="CommandMethods/Children.html#has_commands%3F-instance_method" title="Mamertes::CommandMethods::Children#has_commands? (method)">#has_commands?</a></span>, <span class='object_link'><a href="CommandMethods/Children.html#has_options%3F-instance_method" title="Mamertes::CommandMethods::Children#has_options? (method)">#has_options?</a></span>, <span class='object_link'><a href="CommandMethods/Children.html#option-instance_method" title="Mamertes::CommandMethods::Children#option (method)">#option</a></span></p>
|
499
|
+
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
|
504
|
+
|
505
|
+
|
506
|
+
|
507
|
+
|
508
|
+
<h3 class="inherited">Methods included from <span class='object_link'><a href="CommandMethods/Help.html" title="Mamertes::CommandMethods::Help (module)">CommandMethods::Help</a></span></h3>
|
509
|
+
<p class="inherited"><span class='object_link'><a href="CommandMethods/Help.html#show_help-instance_method" title="Mamertes::CommandMethods::Help#show_help (method)">#show_help</a></span></p>
|
510
|
+
|
511
|
+
<div id="constructor_details" class="method_details_list">
|
512
|
+
<h2>Constructor Details</h2>
|
513
|
+
|
514
|
+
<div class="method_details first">
|
515
|
+
<h3 class="signature first" id="initialize-instance_method">
|
516
|
+
|
517
|
+
- (<tt><span class='object_link'><a href="" title="Mamertes::Application (class)">Application</a></span></tt>) <strong>initialize</strong>(options = {}, &block)
|
518
|
+
|
519
|
+
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
</h3><div class="docstring">
|
524
|
+
<div class="discussion">
|
525
|
+
<p>Creates a new application.</p>
|
526
|
+
|
527
|
+
|
528
|
+
</div>
|
529
|
+
</div>
|
530
|
+
<div class="tags">
|
531
|
+
<p class="tag_title">Parameters:</p>
|
532
|
+
<ul class="param">
|
533
|
+
|
534
|
+
<li>
|
535
|
+
|
536
|
+
<span class='name'>options</span>
|
537
|
+
|
538
|
+
|
539
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
540
|
+
|
541
|
+
|
542
|
+
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
543
|
+
|
544
|
+
|
545
|
+
—
|
546
|
+
<div class='inline'><p>The settings to initialize the application with.</p>
|
547
|
+
</div>
|
548
|
+
|
549
|
+
</li>
|
550
|
+
|
551
|
+
</ul>
|
552
|
+
|
553
|
+
|
554
|
+
</div><table class="source_code">
|
555
|
+
<tr>
|
556
|
+
<td>
|
557
|
+
<pre class="lines">
|
558
|
+
|
559
|
+
|
560
|
+
103
|
561
|
+
104
|
562
|
+
105
|
563
|
+
106
|
564
|
+
107
|
565
|
+
108
|
566
|
+
109
|
567
|
+
110
|
568
|
+
111
|
569
|
+
112
|
570
|
+
113</pre>
|
571
|
+
</td>
|
572
|
+
<td>
|
573
|
+
<pre class="code"><span class="info file"># File 'lib/mamertes/application.rb', line 103</span>
|
574
|
+
|
575
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
576
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
577
|
+
|
578
|
+
<span class='ivar'>@shell</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Bovem</span><span class='op'>::</span><span class='const'>Shell</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span>
|
579
|
+
<span class='ivar'>@console</span> <span class='op'>=</span> <span class='ivar'>@shell</span><span class='period'>.</span><span class='id identifier rubyid_console'>console</span>
|
580
|
+
<span class='ivar'>@skip_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
581
|
+
<span class='ivar'>@show_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
582
|
+
<span class='ivar'>@output_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
583
|
+
|
584
|
+
<span class='id identifier rubyid_help_option'>help_option</span>
|
585
|
+
<span class='kw'>end</span></pre>
|
586
|
+
</td>
|
587
|
+
</tr>
|
588
|
+
</table>
|
589
|
+
</div>
|
590
|
+
|
591
|
+
</div>
|
592
|
+
|
593
|
+
<div id="instance_attr_details" class="attr_details">
|
594
|
+
<h2>Instance Attribute Details</h2>
|
595
|
+
|
596
|
+
|
597
|
+
<span id="console=-instance_method"></span>
|
598
|
+
<div class="method_details first">
|
599
|
+
<h3 class="signature first" id="console-instance_method">
|
600
|
+
|
601
|
+
- (<tt>::Bovem::Console</tt>) <strong>console</strong>
|
602
|
+
|
603
|
+
|
604
|
+
|
605
|
+
|
606
|
+
|
607
|
+
</h3><div class="docstring">
|
608
|
+
<div class="discussion">
|
609
|
+
<p>A console helper.</p>
|
610
|
+
|
611
|
+
|
612
|
+
</div>
|
613
|
+
</div>
|
614
|
+
<div class="tags">
|
615
|
+
|
616
|
+
<p class="tag_title">Returns:</p>
|
617
|
+
<ul class="return">
|
618
|
+
|
619
|
+
<li>
|
620
|
+
|
621
|
+
|
622
|
+
<span class='type'>(<tt>::Bovem::Console</tt>)</span>
|
623
|
+
|
624
|
+
|
625
|
+
|
626
|
+
—
|
627
|
+
<div class='inline'><p>A console helper.</p>
|
628
|
+
</div>
|
629
|
+
|
630
|
+
</li>
|
631
|
+
|
632
|
+
</ul>
|
633
|
+
|
634
|
+
</div><table class="source_code">
|
635
|
+
<tr>
|
636
|
+
<td>
|
637
|
+
<pre class="lines">
|
638
|
+
|
639
|
+
|
640
|
+
72
|
641
|
+
73
|
642
|
+
74
|
643
|
+
75
|
644
|
+
76
|
645
|
+
77
|
646
|
+
78
|
647
|
+
79
|
648
|
+
80
|
649
|
+
81
|
650
|
+
82
|
651
|
+
83
|
652
|
+
84
|
653
|
+
85
|
654
|
+
86
|
655
|
+
87
|
656
|
+
88
|
657
|
+
89
|
658
|
+
90
|
659
|
+
91
|
660
|
+
92
|
661
|
+
93
|
662
|
+
94
|
663
|
+
95
|
664
|
+
96
|
665
|
+
97
|
666
|
+
98
|
667
|
+
99
|
668
|
+
100
|
669
|
+
101
|
670
|
+
102
|
671
|
+
103
|
672
|
+
104
|
673
|
+
105
|
674
|
+
106
|
675
|
+
107
|
676
|
+
108
|
677
|
+
109
|
678
|
+
110
|
679
|
+
111
|
680
|
+
112
|
681
|
+
113
|
682
|
+
114
|
683
|
+
115
|
684
|
+
116
|
685
|
+
117
|
686
|
+
118
|
687
|
+
119
|
688
|
+
120
|
689
|
+
121
|
690
|
+
122
|
691
|
+
123
|
692
|
+
124
|
693
|
+
125
|
694
|
+
126
|
695
|
+
127
|
696
|
+
128
|
697
|
+
129
|
698
|
+
130
|
699
|
+
131
|
700
|
+
132
|
701
|
+
133
|
702
|
+
134
|
703
|
+
135
|
704
|
+
136
|
705
|
+
137
|
706
|
+
138
|
707
|
+
139
|
708
|
+
140
|
709
|
+
141
|
710
|
+
142
|
711
|
+
143
|
712
|
+
144
|
713
|
+
145
|
714
|
+
146
|
715
|
+
147
|
716
|
+
148
|
717
|
+
149
|
718
|
+
150
|
719
|
+
151
|
720
|
+
152
|
721
|
+
153
|
722
|
+
154
|
723
|
+
155
|
724
|
+
156
|
725
|
+
157
|
726
|
+
158
|
727
|
+
159
|
728
|
+
160
|
729
|
+
161
|
730
|
+
162
|
731
|
+
163
|
732
|
+
164
|
733
|
+
165
|
734
|
+
166
|
735
|
+
167
|
736
|
+
168
|
737
|
+
169
|
738
|
+
170
|
739
|
+
171
|
740
|
+
172
|
741
|
+
173
|
742
|
+
174
|
743
|
+
175
|
744
|
+
176
|
745
|
+
177
|
746
|
+
178
|
747
|
+
179
|
748
|
+
180
|
749
|
+
181
|
750
|
+
182
|
751
|
+
183
|
752
|
+
184
|
753
|
+
185
|
754
|
+
186
|
755
|
+
187
|
756
|
+
188
|
757
|
+
189
|
758
|
+
190
|
759
|
+
191
|
760
|
+
192
|
761
|
+
193
|
762
|
+
194
|
763
|
+
195
|
764
|
+
196
|
765
|
+
197
|
766
|
+
198
|
767
|
+
199
|
768
|
+
200
|
769
|
+
201
|
770
|
+
202
|
771
|
+
203
|
772
|
+
204
|
773
|
+
205</pre>
|
774
|
+
</td>
|
775
|
+
<td>
|
776
|
+
<pre class="code"><span class="info file"># File 'lib/mamertes/application.rb', line 72</span>
|
777
|
+
|
778
|
+
<span class='kw'>class</span> <span class='const'>Application</span> <span class='op'><</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Command</span>
|
779
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:version</span>
|
780
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:shell</span>
|
781
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:console</span>
|
782
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:skip_commands</span>
|
783
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:show_commands</span>
|
784
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:output_commands</span>
|
785
|
+
|
786
|
+
<span class='comment'># Initializes a new Mamertes application.
|
787
|
+
</span> <span class='comment'>#
|
788
|
+
</span> <span class='comment'># In options, you can override the command line arguments with `:__args__`, and you can skip execution by specifying `run: false`.
|
789
|
+
</span> <span class='comment'>#
|
790
|
+
</span> <span class='comment'># @see Command#setup_with
|
791
|
+
</span> <span class='comment'>#
|
792
|
+
</span> <span class='comment'># @param options [Hash] The settings to initialize the application with.
|
793
|
+
</span> <span class='comment'># @return [Application] The created application.
|
794
|
+
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
795
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Error</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Application</span><span class='comma'>,</span> <span class='symbol'>:missing_block</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_localize_on_locale'>localize_on_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='symbol'>:missing_app_block</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_block_given?'>block_given?</span>
|
796
|
+
<span class='id identifier rubyid_run'>run</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='id identifier rubyid_setup_application_option'>setup_application_option</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
|
797
|
+
|
798
|
+
<span class='kw'>begin</span>
|
799
|
+
<span class='id identifier rubyid_create_application'>create_application</span><span class='lparen'>(</span><span class='id identifier rubyid_run'>run</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
800
|
+
<span class='kw'>rescue</span> <span class='op'>=></span> <span class='id identifier rubyid_e'>e</span>
|
801
|
+
<span class='const'>Kernel</span><span class='period'>.</span><span class='id identifier rubyid_puts'>puts</span><span class='lparen'>(</span><span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span>
|
802
|
+
<span class='const'>Kernel</span><span class='period'>.</span><span class='id identifier rubyid_exit'>exit</span><span class='lparen'>(</span><span class='int'>1</span><span class='rparen'>)</span>
|
803
|
+
<span class='kw'>end</span>
|
804
|
+
<span class='kw'>end</span>
|
805
|
+
|
806
|
+
<span class='comment'># Creates a new application.
|
807
|
+
</span> <span class='comment'>#
|
808
|
+
</span> <span class='comment'># @param options [Hash] The settings to initialize the application with.
|
809
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
810
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
811
|
+
|
812
|
+
<span class='ivar'>@shell</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Bovem</span><span class='op'>::</span><span class='const'>Shell</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span>
|
813
|
+
<span class='ivar'>@console</span> <span class='op'>=</span> <span class='ivar'>@shell</span><span class='period'>.</span><span class='id identifier rubyid_console'>console</span>
|
814
|
+
<span class='ivar'>@skip_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
815
|
+
<span class='ivar'>@show_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
816
|
+
<span class='ivar'>@output_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
817
|
+
|
818
|
+
<span class='id identifier rubyid_help_option'>help_option</span>
|
819
|
+
<span class='kw'>end</span>
|
820
|
+
|
821
|
+
<span class='comment'># Reads and optionally sets the version of this application.
|
822
|
+
</span> <span class='comment'>#
|
823
|
+
</span> <span class='comment'># @param value [String|nil] The new version of this application.
|
824
|
+
</span> <span class='comment'># @return [String|nil] The version of this application.
|
825
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_version'>version</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
826
|
+
<span class='ivar'>@version</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span> <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
827
|
+
<span class='ivar'>@version</span>
|
828
|
+
<span class='kw'>end</span>
|
829
|
+
|
830
|
+
<span class='comment'># Executes this application.
|
831
|
+
</span> <span class='comment'>#
|
832
|
+
</span> <span class='comment'># @param args [Array] The command line to pass to this application. Defaults to `ARGV`.
|
833
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
834
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span> <span class='op'>||</span> <span class='const'>ARGV</span><span class='rparen'>)</span>
|
835
|
+
<span class='kw'>end</span>
|
836
|
+
|
837
|
+
<span class='comment'># Adds a help command and a help option to this application.
|
838
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_help_option'>help_option</span>
|
839
|
+
<span class='id identifier rubyid_command'>command</span><span class='lparen'>(</span><span class='symbol'>:help</span><span class='comma'>,</span> <span class='label'>description:</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_command_description'>help_command_description</span><span class='rparen'>)</span> <span class='kw'>do</span>
|
840
|
+
<span class='id identifier rubyid_action'>action</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_command'>command</span><span class='op'>|</span> <span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_command_help'>command_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
841
|
+
<span class='kw'>end</span>
|
842
|
+
|
843
|
+
<span class='id identifier rubyid_option'>option</span><span class='lparen'>(</span><span class='symbol'>:help</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_option_short_form'>help_option_short_form</span><span class='comma'>,</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_option_long_form'>help_option_long_form</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='label'>help:</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_message'>help_message</span><span class='rparen'>)</span><span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_application'>application</span><span class='comma'>,</span> <span class='id identifier rubyid__'>_</span><span class='op'>|</span> <span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_show_help'>show_help</span> <span class='rbrace'>}</span>
|
844
|
+
<span class='kw'>end</span>
|
845
|
+
|
846
|
+
<span class='comment'># The name of the current executable.
|
847
|
+
</span> <span class='comment'>#
|
848
|
+
</span> <span class='comment'># @return [String] The name of the current executable.
|
849
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_executable_name'>executable_name</span>
|
850
|
+
<span class='gvar'>$0</span>
|
851
|
+
<span class='kw'>end</span>
|
852
|
+
|
853
|
+
<span class='comment'># Shows a help about a command.
|
854
|
+
</span> <span class='comment'>#
|
855
|
+
</span> <span class='comment'># @param command [Command] The command to show help for.
|
856
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_command_help'>command_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span>
|
857
|
+
<span class='id identifier rubyid_fetch_commands_for_help'>fetch_commands_for_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_arg'>arg</span><span class='op'>|</span>
|
858
|
+
<span class='comment'># Find the command across
|
859
|
+
</span> <span class='id identifier rubyid_next_command'>next_command</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Parser</span><span class='period'>.</span><span class='id identifier rubyid_find_command'>find_command</span><span class='lparen'>(</span><span class='id identifier rubyid_arg'>arg</span><span class='comma'>,</span> <span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
860
|
+
|
861
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_next_command'>next_command</span> <span class='kw'>then</span>
|
862
|
+
<span class='id identifier rubyid_command'>command</span> <span class='op'>=</span> <span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_commands'>commands</span><span class='lbracket'>[</span><span class='id identifier rubyid_next_command'>next_command</span><span class='lbracket'>[</span><span class='symbol'>:name</span><span class='rbracket'>]</span><span class='rbracket'>]</span>
|
863
|
+
<span class='kw'>else</span>
|
864
|
+
<span class='kw'>break</span>
|
865
|
+
<span class='kw'>end</span>
|
866
|
+
<span class='kw'>end</span>
|
867
|
+
|
868
|
+
<span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_show_help'>show_help</span>
|
869
|
+
<span class='kw'>end</span>
|
870
|
+
|
871
|
+
<span class='comment'># Runs a command into the shell.
|
872
|
+
</span> <span class='comment'>#
|
873
|
+
</span> <span class='comment'># @param command [String] The string to run.
|
874
|
+
</span> <span class='comment'># @param message [String] A message to show before running.
|
875
|
+
</span> <span class='comment'># @param show_exit [Boolean] If show the exit status.
|
876
|
+
</span> <span class='comment'># @param fatal [Boolean] If quit in case of fatal errors.
|
877
|
+
</span> <span class='comment'># @return [Hash] An hash with `status` and `output` keys.
|
878
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_run'>run</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_show_exit'>show_exit</span> <span class='op'>=</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='id identifier rubyid_fatal'>fatal</span> <span class='op'>=</span> <span class='kw'>true</span><span class='rparen'>)</span>
|
879
|
+
<span class='ivar'>@shell</span><span class='period'>.</span><span class='id identifier rubyid_run'>run</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>!</span><span class='ivar'>@skip_commands</span><span class='comma'>,</span> <span class='id identifier rubyid_show_exit'>show_exit</span><span class='comma'>,</span> <span class='ivar'>@output_commands</span><span class='comma'>,</span> <span class='ivar'>@show_commands</span><span class='comma'>,</span> <span class='id identifier rubyid_fatal'>fatal</span><span class='rparen'>)</span>
|
880
|
+
<span class='kw'>end</span>
|
881
|
+
|
882
|
+
<span class='id identifier rubyid_private'>private</span>
|
883
|
+
<span class='comment'># Setup options for application creation.
|
884
|
+
</span> <span class='comment'>#
|
885
|
+
</span> <span class='comment'># @param options [Hash] The options to setups.
|
886
|
+
</span> <span class='comment'># @return [Array] If to run the application, the arguments and the specified options.
|
887
|
+
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_setup_application_option'>setup_application_option</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
|
888
|
+
<span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='label'>name:</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_localize_on_locale'>localize_on_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='symbol'>:default_application_name</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='label'>parent:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>application:</span> <span class='kw'>nil</span><span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_ensure_hash'>ensure_hash</span><span class='rparen'>)</span>
|
889
|
+
<span class='id identifier rubyid_run'>run</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:run</span><span class='rparen'>)</span>
|
890
|
+
<span class='lbracket'>[</span><span class='lparen'>(</span><span class='op'>!</span><span class='id identifier rubyid_run'>run</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> <span class='op'>?</span> <span class='id identifier rubyid_run'>run</span> <span class='op'>:</span> <span class='kw'>true</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_boolean'>to_boolean</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:__args__</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='rbracket'>]</span>
|
891
|
+
<span class='kw'>end</span>
|
892
|
+
|
893
|
+
<span class='comment'># Create the application.
|
894
|
+
</span> <span class='comment'>#
|
895
|
+
</span> <span class='comment'># @param run [Boolean ]If to run the application.
|
896
|
+
</span> <span class='comment'># @param args [Hash] The arguments to use for running.
|
897
|
+
</span> <span class='comment'># @param options [Hash] The options of the application.
|
898
|
+
</span> <span class='comment'># @return [Application] The new application.
|
899
|
+
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create_application'>create_application</span><span class='lparen'>(</span><span class='id identifier rubyid_run'>run</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
900
|
+
<span class='id identifier rubyid_application'>application</span> <span class='op'>=</span> <span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
901
|
+
<span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_application'>application</span> <span class='op'>&&</span> <span class='id identifier rubyid_run'>run</span>
|
902
|
+
<span class='id identifier rubyid_application'>application</span>
|
903
|
+
<span class='kw'>end</span>
|
904
|
+
|
905
|
+
<span class='comment'># Fetch a command list for showing help.
|
906
|
+
</span> <span class='comment'>#
|
907
|
+
</span> <span class='comment'># @param command [Command] The command to show help for.
|
908
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_fetch_commands_for_help'>fetch_commands_for_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span>
|
909
|
+
<span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_c'>c</span><span class='op'>|</span> <span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_split'>split</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>:</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:strip</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_select'>select</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:present?</span><span class='rparen'>)</span>
|
910
|
+
<span class='kw'>end</span>
|
911
|
+
<span class='kw'>end</span></pre>
|
912
|
+
</td>
|
913
|
+
</tr>
|
914
|
+
</table>
|
915
|
+
</div>
|
916
|
+
|
917
|
+
|
918
|
+
<span id="output_commands=-instance_method"></span>
|
919
|
+
<div class="method_details ">
|
920
|
+
<h3 class="signature " id="output_commands-instance_method">
|
921
|
+
|
922
|
+
- (<tt>Boolean</tt>) <strong>output_commands</strong>
|
923
|
+
|
924
|
+
|
925
|
+
|
926
|
+
|
927
|
+
|
928
|
+
</h3><div class="docstring">
|
929
|
+
<div class="discussion">
|
930
|
+
<p>If to show the output of the commands run via <span class='object_link'><a href="#run-instance_method" title="Mamertes::Application#run (method)">#run</a></span>.</p>
|
931
|
+
|
932
|
+
|
933
|
+
</div>
|
934
|
+
</div>
|
935
|
+
<div class="tags">
|
936
|
+
|
937
|
+
<p class="tag_title">Returns:</p>
|
938
|
+
<ul class="return">
|
939
|
+
|
940
|
+
<li>
|
941
|
+
|
942
|
+
|
943
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
944
|
+
|
945
|
+
|
946
|
+
|
947
|
+
—
|
948
|
+
<div class='inline'><p>If to show the output of the commands run via <span class='object_link'><a href="#run-instance_method" title="Mamertes::Application#run (method)">#run</a></span>.</p>
|
949
|
+
</div>
|
950
|
+
|
951
|
+
</li>
|
952
|
+
|
953
|
+
</ul>
|
954
|
+
|
955
|
+
</div><table class="source_code">
|
956
|
+
<tr>
|
957
|
+
<td>
|
958
|
+
<pre class="lines">
|
959
|
+
|
960
|
+
|
961
|
+
72
|
962
|
+
73
|
963
|
+
74
|
964
|
+
75
|
965
|
+
76
|
966
|
+
77
|
967
|
+
78
|
968
|
+
79
|
969
|
+
80
|
970
|
+
81
|
971
|
+
82
|
972
|
+
83
|
973
|
+
84
|
974
|
+
85
|
975
|
+
86
|
976
|
+
87
|
977
|
+
88
|
978
|
+
89
|
979
|
+
90
|
980
|
+
91
|
981
|
+
92
|
982
|
+
93
|
983
|
+
94
|
984
|
+
95
|
985
|
+
96
|
986
|
+
97
|
987
|
+
98
|
988
|
+
99
|
989
|
+
100
|
990
|
+
101
|
991
|
+
102
|
992
|
+
103
|
993
|
+
104
|
994
|
+
105
|
995
|
+
106
|
996
|
+
107
|
997
|
+
108
|
998
|
+
109
|
999
|
+
110
|
1000
|
+
111
|
1001
|
+
112
|
1002
|
+
113
|
1003
|
+
114
|
1004
|
+
115
|
1005
|
+
116
|
1006
|
+
117
|
1007
|
+
118
|
1008
|
+
119
|
1009
|
+
120
|
1010
|
+
121
|
1011
|
+
122
|
1012
|
+
123
|
1013
|
+
124
|
1014
|
+
125
|
1015
|
+
126
|
1016
|
+
127
|
1017
|
+
128
|
1018
|
+
129
|
1019
|
+
130
|
1020
|
+
131
|
1021
|
+
132
|
1022
|
+
133
|
1023
|
+
134
|
1024
|
+
135
|
1025
|
+
136
|
1026
|
+
137
|
1027
|
+
138
|
1028
|
+
139
|
1029
|
+
140
|
1030
|
+
141
|
1031
|
+
142
|
1032
|
+
143
|
1033
|
+
144
|
1034
|
+
145
|
1035
|
+
146
|
1036
|
+
147
|
1037
|
+
148
|
1038
|
+
149
|
1039
|
+
150
|
1040
|
+
151
|
1041
|
+
152
|
1042
|
+
153
|
1043
|
+
154
|
1044
|
+
155
|
1045
|
+
156
|
1046
|
+
157
|
1047
|
+
158
|
1048
|
+
159
|
1049
|
+
160
|
1050
|
+
161
|
1051
|
+
162
|
1052
|
+
163
|
1053
|
+
164
|
1054
|
+
165
|
1055
|
+
166
|
1056
|
+
167
|
1057
|
+
168
|
1058
|
+
169
|
1059
|
+
170
|
1060
|
+
171
|
1061
|
+
172
|
1062
|
+
173
|
1063
|
+
174
|
1064
|
+
175
|
1065
|
+
176
|
1066
|
+
177
|
1067
|
+
178
|
1068
|
+
179
|
1069
|
+
180
|
1070
|
+
181
|
1071
|
+
182
|
1072
|
+
183
|
1073
|
+
184
|
1074
|
+
185
|
1075
|
+
186
|
1076
|
+
187
|
1077
|
+
188
|
1078
|
+
189
|
1079
|
+
190
|
1080
|
+
191
|
1081
|
+
192
|
1082
|
+
193
|
1083
|
+
194
|
1084
|
+
195
|
1085
|
+
196
|
1086
|
+
197
|
1087
|
+
198
|
1088
|
+
199
|
1089
|
+
200
|
1090
|
+
201
|
1091
|
+
202
|
1092
|
+
203
|
1093
|
+
204
|
1094
|
+
205</pre>
|
1095
|
+
</td>
|
1096
|
+
<td>
|
1097
|
+
<pre class="code"><span class="info file"># File 'lib/mamertes/application.rb', line 72</span>
|
1098
|
+
|
1099
|
+
<span class='kw'>class</span> <span class='const'>Application</span> <span class='op'><</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Command</span>
|
1100
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:version</span>
|
1101
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:shell</span>
|
1102
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:console</span>
|
1103
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:skip_commands</span>
|
1104
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:show_commands</span>
|
1105
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:output_commands</span>
|
1106
|
+
|
1107
|
+
<span class='comment'># Initializes a new Mamertes application.
|
1108
|
+
</span> <span class='comment'>#
|
1109
|
+
</span> <span class='comment'># In options, you can override the command line arguments with `:__args__`, and you can skip execution by specifying `run: false`.
|
1110
|
+
</span> <span class='comment'>#
|
1111
|
+
</span> <span class='comment'># @see Command#setup_with
|
1112
|
+
</span> <span class='comment'>#
|
1113
|
+
</span> <span class='comment'># @param options [Hash] The settings to initialize the application with.
|
1114
|
+
</span> <span class='comment'># @return [Application] The created application.
|
1115
|
+
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1116
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Error</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Application</span><span class='comma'>,</span> <span class='symbol'>:missing_block</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_localize_on_locale'>localize_on_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='symbol'>:missing_app_block</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_block_given?'>block_given?</span>
|
1117
|
+
<span class='id identifier rubyid_run'>run</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='id identifier rubyid_setup_application_option'>setup_application_option</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
|
1118
|
+
|
1119
|
+
<span class='kw'>begin</span>
|
1120
|
+
<span class='id identifier rubyid_create_application'>create_application</span><span class='lparen'>(</span><span class='id identifier rubyid_run'>run</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1121
|
+
<span class='kw'>rescue</span> <span class='op'>=></span> <span class='id identifier rubyid_e'>e</span>
|
1122
|
+
<span class='const'>Kernel</span><span class='period'>.</span><span class='id identifier rubyid_puts'>puts</span><span class='lparen'>(</span><span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span>
|
1123
|
+
<span class='const'>Kernel</span><span class='period'>.</span><span class='id identifier rubyid_exit'>exit</span><span class='lparen'>(</span><span class='int'>1</span><span class='rparen'>)</span>
|
1124
|
+
<span class='kw'>end</span>
|
1125
|
+
<span class='kw'>end</span>
|
1126
|
+
|
1127
|
+
<span class='comment'># Creates a new application.
|
1128
|
+
</span> <span class='comment'>#
|
1129
|
+
</span> <span class='comment'># @param options [Hash] The settings to initialize the application with.
|
1130
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1131
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1132
|
+
|
1133
|
+
<span class='ivar'>@shell</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Bovem</span><span class='op'>::</span><span class='const'>Shell</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span>
|
1134
|
+
<span class='ivar'>@console</span> <span class='op'>=</span> <span class='ivar'>@shell</span><span class='period'>.</span><span class='id identifier rubyid_console'>console</span>
|
1135
|
+
<span class='ivar'>@skip_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
1136
|
+
<span class='ivar'>@show_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
1137
|
+
<span class='ivar'>@output_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
1138
|
+
|
1139
|
+
<span class='id identifier rubyid_help_option'>help_option</span>
|
1140
|
+
<span class='kw'>end</span>
|
1141
|
+
|
1142
|
+
<span class='comment'># Reads and optionally sets the version of this application.
|
1143
|
+
</span> <span class='comment'>#
|
1144
|
+
</span> <span class='comment'># @param value [String|nil] The new version of this application.
|
1145
|
+
</span> <span class='comment'># @return [String|nil] The version of this application.
|
1146
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_version'>version</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
1147
|
+
<span class='ivar'>@version</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span> <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
1148
|
+
<span class='ivar'>@version</span>
|
1149
|
+
<span class='kw'>end</span>
|
1150
|
+
|
1151
|
+
<span class='comment'># Executes this application.
|
1152
|
+
</span> <span class='comment'>#
|
1153
|
+
</span> <span class='comment'># @param args [Array] The command line to pass to this application. Defaults to `ARGV`.
|
1154
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
1155
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span> <span class='op'>||</span> <span class='const'>ARGV</span><span class='rparen'>)</span>
|
1156
|
+
<span class='kw'>end</span>
|
1157
|
+
|
1158
|
+
<span class='comment'># Adds a help command and a help option to this application.
|
1159
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_help_option'>help_option</span>
|
1160
|
+
<span class='id identifier rubyid_command'>command</span><span class='lparen'>(</span><span class='symbol'>:help</span><span class='comma'>,</span> <span class='label'>description:</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_command_description'>help_command_description</span><span class='rparen'>)</span> <span class='kw'>do</span>
|
1161
|
+
<span class='id identifier rubyid_action'>action</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_command'>command</span><span class='op'>|</span> <span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_command_help'>command_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
1162
|
+
<span class='kw'>end</span>
|
1163
|
+
|
1164
|
+
<span class='id identifier rubyid_option'>option</span><span class='lparen'>(</span><span class='symbol'>:help</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_option_short_form'>help_option_short_form</span><span class='comma'>,</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_option_long_form'>help_option_long_form</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='label'>help:</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_message'>help_message</span><span class='rparen'>)</span><span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_application'>application</span><span class='comma'>,</span> <span class='id identifier rubyid__'>_</span><span class='op'>|</span> <span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_show_help'>show_help</span> <span class='rbrace'>}</span>
|
1165
|
+
<span class='kw'>end</span>
|
1166
|
+
|
1167
|
+
<span class='comment'># The name of the current executable.
|
1168
|
+
</span> <span class='comment'>#
|
1169
|
+
</span> <span class='comment'># @return [String] The name of the current executable.
|
1170
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_executable_name'>executable_name</span>
|
1171
|
+
<span class='gvar'>$0</span>
|
1172
|
+
<span class='kw'>end</span>
|
1173
|
+
|
1174
|
+
<span class='comment'># Shows a help about a command.
|
1175
|
+
</span> <span class='comment'>#
|
1176
|
+
</span> <span class='comment'># @param command [Command] The command to show help for.
|
1177
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_command_help'>command_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span>
|
1178
|
+
<span class='id identifier rubyid_fetch_commands_for_help'>fetch_commands_for_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_arg'>arg</span><span class='op'>|</span>
|
1179
|
+
<span class='comment'># Find the command across
|
1180
|
+
</span> <span class='id identifier rubyid_next_command'>next_command</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Parser</span><span class='period'>.</span><span class='id identifier rubyid_find_command'>find_command</span><span class='lparen'>(</span><span class='id identifier rubyid_arg'>arg</span><span class='comma'>,</span> <span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
1181
|
+
|
1182
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_next_command'>next_command</span> <span class='kw'>then</span>
|
1183
|
+
<span class='id identifier rubyid_command'>command</span> <span class='op'>=</span> <span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_commands'>commands</span><span class='lbracket'>[</span><span class='id identifier rubyid_next_command'>next_command</span><span class='lbracket'>[</span><span class='symbol'>:name</span><span class='rbracket'>]</span><span class='rbracket'>]</span>
|
1184
|
+
<span class='kw'>else</span>
|
1185
|
+
<span class='kw'>break</span>
|
1186
|
+
<span class='kw'>end</span>
|
1187
|
+
<span class='kw'>end</span>
|
1188
|
+
|
1189
|
+
<span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_show_help'>show_help</span>
|
1190
|
+
<span class='kw'>end</span>
|
1191
|
+
|
1192
|
+
<span class='comment'># Runs a command into the shell.
|
1193
|
+
</span> <span class='comment'>#
|
1194
|
+
</span> <span class='comment'># @param command [String] The string to run.
|
1195
|
+
</span> <span class='comment'># @param message [String] A message to show before running.
|
1196
|
+
</span> <span class='comment'># @param show_exit [Boolean] If show the exit status.
|
1197
|
+
</span> <span class='comment'># @param fatal [Boolean] If quit in case of fatal errors.
|
1198
|
+
</span> <span class='comment'># @return [Hash] An hash with `status` and `output` keys.
|
1199
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_run'>run</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_show_exit'>show_exit</span> <span class='op'>=</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='id identifier rubyid_fatal'>fatal</span> <span class='op'>=</span> <span class='kw'>true</span><span class='rparen'>)</span>
|
1200
|
+
<span class='ivar'>@shell</span><span class='period'>.</span><span class='id identifier rubyid_run'>run</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>!</span><span class='ivar'>@skip_commands</span><span class='comma'>,</span> <span class='id identifier rubyid_show_exit'>show_exit</span><span class='comma'>,</span> <span class='ivar'>@output_commands</span><span class='comma'>,</span> <span class='ivar'>@show_commands</span><span class='comma'>,</span> <span class='id identifier rubyid_fatal'>fatal</span><span class='rparen'>)</span>
|
1201
|
+
<span class='kw'>end</span>
|
1202
|
+
|
1203
|
+
<span class='id identifier rubyid_private'>private</span>
|
1204
|
+
<span class='comment'># Setup options for application creation.
|
1205
|
+
</span> <span class='comment'>#
|
1206
|
+
</span> <span class='comment'># @param options [Hash] The options to setups.
|
1207
|
+
</span> <span class='comment'># @return [Array] If to run the application, the arguments and the specified options.
|
1208
|
+
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_setup_application_option'>setup_application_option</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
|
1209
|
+
<span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='label'>name:</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_localize_on_locale'>localize_on_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='symbol'>:default_application_name</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='label'>parent:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>application:</span> <span class='kw'>nil</span><span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_ensure_hash'>ensure_hash</span><span class='rparen'>)</span>
|
1210
|
+
<span class='id identifier rubyid_run'>run</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:run</span><span class='rparen'>)</span>
|
1211
|
+
<span class='lbracket'>[</span><span class='lparen'>(</span><span class='op'>!</span><span class='id identifier rubyid_run'>run</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> <span class='op'>?</span> <span class='id identifier rubyid_run'>run</span> <span class='op'>:</span> <span class='kw'>true</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_boolean'>to_boolean</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:__args__</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='rbracket'>]</span>
|
1212
|
+
<span class='kw'>end</span>
|
1213
|
+
|
1214
|
+
<span class='comment'># Create the application.
|
1215
|
+
</span> <span class='comment'>#
|
1216
|
+
</span> <span class='comment'># @param run [Boolean ]If to run the application.
|
1217
|
+
</span> <span class='comment'># @param args [Hash] The arguments to use for running.
|
1218
|
+
</span> <span class='comment'># @param options [Hash] The options of the application.
|
1219
|
+
</span> <span class='comment'># @return [Application] The new application.
|
1220
|
+
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create_application'>create_application</span><span class='lparen'>(</span><span class='id identifier rubyid_run'>run</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1221
|
+
<span class='id identifier rubyid_application'>application</span> <span class='op'>=</span> <span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1222
|
+
<span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_application'>application</span> <span class='op'>&&</span> <span class='id identifier rubyid_run'>run</span>
|
1223
|
+
<span class='id identifier rubyid_application'>application</span>
|
1224
|
+
<span class='kw'>end</span>
|
1225
|
+
|
1226
|
+
<span class='comment'># Fetch a command list for showing help.
|
1227
|
+
</span> <span class='comment'>#
|
1228
|
+
</span> <span class='comment'># @param command [Command] The command to show help for.
|
1229
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_fetch_commands_for_help'>fetch_commands_for_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span>
|
1230
|
+
<span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_c'>c</span><span class='op'>|</span> <span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_split'>split</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>:</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:strip</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_select'>select</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:present?</span><span class='rparen'>)</span>
|
1231
|
+
<span class='kw'>end</span>
|
1232
|
+
<span class='kw'>end</span></pre>
|
1233
|
+
</td>
|
1234
|
+
</tr>
|
1235
|
+
</table>
|
1236
|
+
</div>
|
1237
|
+
|
1238
|
+
|
1239
|
+
<span id="shell=-instance_method"></span>
|
1240
|
+
<div class="method_details ">
|
1241
|
+
<h3 class="signature " id="shell-instance_method">
|
1242
|
+
|
1243
|
+
- (<tt>::Bovem::Shell</tt>) <strong>shell</strong>
|
1244
|
+
|
1245
|
+
|
1246
|
+
|
1247
|
+
|
1248
|
+
|
1249
|
+
</h3><div class="docstring">
|
1250
|
+
<div class="discussion">
|
1251
|
+
<p>A shell helper.</p>
|
1252
|
+
|
1253
|
+
|
1254
|
+
</div>
|
1255
|
+
</div>
|
1256
|
+
<div class="tags">
|
1257
|
+
|
1258
|
+
<p class="tag_title">Returns:</p>
|
1259
|
+
<ul class="return">
|
1260
|
+
|
1261
|
+
<li>
|
1262
|
+
|
1263
|
+
|
1264
|
+
<span class='type'>(<tt>::Bovem::Shell</tt>)</span>
|
1265
|
+
|
1266
|
+
|
1267
|
+
|
1268
|
+
—
|
1269
|
+
<div class='inline'><p>A shell helper.</p>
|
1270
|
+
</div>
|
1271
|
+
|
1272
|
+
</li>
|
1273
|
+
|
1274
|
+
</ul>
|
1275
|
+
|
1276
|
+
</div><table class="source_code">
|
1277
|
+
<tr>
|
1278
|
+
<td>
|
1279
|
+
<pre class="lines">
|
1280
|
+
|
1281
|
+
|
1282
|
+
72
|
1283
|
+
73
|
1284
|
+
74
|
1285
|
+
75
|
1286
|
+
76
|
1287
|
+
77
|
1288
|
+
78
|
1289
|
+
79
|
1290
|
+
80
|
1291
|
+
81
|
1292
|
+
82
|
1293
|
+
83
|
1294
|
+
84
|
1295
|
+
85
|
1296
|
+
86
|
1297
|
+
87
|
1298
|
+
88
|
1299
|
+
89
|
1300
|
+
90
|
1301
|
+
91
|
1302
|
+
92
|
1303
|
+
93
|
1304
|
+
94
|
1305
|
+
95
|
1306
|
+
96
|
1307
|
+
97
|
1308
|
+
98
|
1309
|
+
99
|
1310
|
+
100
|
1311
|
+
101
|
1312
|
+
102
|
1313
|
+
103
|
1314
|
+
104
|
1315
|
+
105
|
1316
|
+
106
|
1317
|
+
107
|
1318
|
+
108
|
1319
|
+
109
|
1320
|
+
110
|
1321
|
+
111
|
1322
|
+
112
|
1323
|
+
113
|
1324
|
+
114
|
1325
|
+
115
|
1326
|
+
116
|
1327
|
+
117
|
1328
|
+
118
|
1329
|
+
119
|
1330
|
+
120
|
1331
|
+
121
|
1332
|
+
122
|
1333
|
+
123
|
1334
|
+
124
|
1335
|
+
125
|
1336
|
+
126
|
1337
|
+
127
|
1338
|
+
128
|
1339
|
+
129
|
1340
|
+
130
|
1341
|
+
131
|
1342
|
+
132
|
1343
|
+
133
|
1344
|
+
134
|
1345
|
+
135
|
1346
|
+
136
|
1347
|
+
137
|
1348
|
+
138
|
1349
|
+
139
|
1350
|
+
140
|
1351
|
+
141
|
1352
|
+
142
|
1353
|
+
143
|
1354
|
+
144
|
1355
|
+
145
|
1356
|
+
146
|
1357
|
+
147
|
1358
|
+
148
|
1359
|
+
149
|
1360
|
+
150
|
1361
|
+
151
|
1362
|
+
152
|
1363
|
+
153
|
1364
|
+
154
|
1365
|
+
155
|
1366
|
+
156
|
1367
|
+
157
|
1368
|
+
158
|
1369
|
+
159
|
1370
|
+
160
|
1371
|
+
161
|
1372
|
+
162
|
1373
|
+
163
|
1374
|
+
164
|
1375
|
+
165
|
1376
|
+
166
|
1377
|
+
167
|
1378
|
+
168
|
1379
|
+
169
|
1380
|
+
170
|
1381
|
+
171
|
1382
|
+
172
|
1383
|
+
173
|
1384
|
+
174
|
1385
|
+
175
|
1386
|
+
176
|
1387
|
+
177
|
1388
|
+
178
|
1389
|
+
179
|
1390
|
+
180
|
1391
|
+
181
|
1392
|
+
182
|
1393
|
+
183
|
1394
|
+
184
|
1395
|
+
185
|
1396
|
+
186
|
1397
|
+
187
|
1398
|
+
188
|
1399
|
+
189
|
1400
|
+
190
|
1401
|
+
191
|
1402
|
+
192
|
1403
|
+
193
|
1404
|
+
194
|
1405
|
+
195
|
1406
|
+
196
|
1407
|
+
197
|
1408
|
+
198
|
1409
|
+
199
|
1410
|
+
200
|
1411
|
+
201
|
1412
|
+
202
|
1413
|
+
203
|
1414
|
+
204
|
1415
|
+
205</pre>
|
1416
|
+
</td>
|
1417
|
+
<td>
|
1418
|
+
<pre class="code"><span class="info file"># File 'lib/mamertes/application.rb', line 72</span>
|
1419
|
+
|
1420
|
+
<span class='kw'>class</span> <span class='const'>Application</span> <span class='op'><</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Command</span>
|
1421
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:version</span>
|
1422
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:shell</span>
|
1423
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:console</span>
|
1424
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:skip_commands</span>
|
1425
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:show_commands</span>
|
1426
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:output_commands</span>
|
1427
|
+
|
1428
|
+
<span class='comment'># Initializes a new Mamertes application.
|
1429
|
+
</span> <span class='comment'>#
|
1430
|
+
</span> <span class='comment'># In options, you can override the command line arguments with `:__args__`, and you can skip execution by specifying `run: false`.
|
1431
|
+
</span> <span class='comment'>#
|
1432
|
+
</span> <span class='comment'># @see Command#setup_with
|
1433
|
+
</span> <span class='comment'>#
|
1434
|
+
</span> <span class='comment'># @param options [Hash] The settings to initialize the application with.
|
1435
|
+
</span> <span class='comment'># @return [Application] The created application.
|
1436
|
+
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1437
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Error</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Application</span><span class='comma'>,</span> <span class='symbol'>:missing_block</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_localize_on_locale'>localize_on_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='symbol'>:missing_app_block</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_block_given?'>block_given?</span>
|
1438
|
+
<span class='id identifier rubyid_run'>run</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='id identifier rubyid_setup_application_option'>setup_application_option</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
|
1439
|
+
|
1440
|
+
<span class='kw'>begin</span>
|
1441
|
+
<span class='id identifier rubyid_create_application'>create_application</span><span class='lparen'>(</span><span class='id identifier rubyid_run'>run</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1442
|
+
<span class='kw'>rescue</span> <span class='op'>=></span> <span class='id identifier rubyid_e'>e</span>
|
1443
|
+
<span class='const'>Kernel</span><span class='period'>.</span><span class='id identifier rubyid_puts'>puts</span><span class='lparen'>(</span><span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span>
|
1444
|
+
<span class='const'>Kernel</span><span class='period'>.</span><span class='id identifier rubyid_exit'>exit</span><span class='lparen'>(</span><span class='int'>1</span><span class='rparen'>)</span>
|
1445
|
+
<span class='kw'>end</span>
|
1446
|
+
<span class='kw'>end</span>
|
1447
|
+
|
1448
|
+
<span class='comment'># Creates a new application.
|
1449
|
+
</span> <span class='comment'>#
|
1450
|
+
</span> <span class='comment'># @param options [Hash] The settings to initialize the application with.
|
1451
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1452
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1453
|
+
|
1454
|
+
<span class='ivar'>@shell</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Bovem</span><span class='op'>::</span><span class='const'>Shell</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span>
|
1455
|
+
<span class='ivar'>@console</span> <span class='op'>=</span> <span class='ivar'>@shell</span><span class='period'>.</span><span class='id identifier rubyid_console'>console</span>
|
1456
|
+
<span class='ivar'>@skip_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
1457
|
+
<span class='ivar'>@show_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
1458
|
+
<span class='ivar'>@output_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
1459
|
+
|
1460
|
+
<span class='id identifier rubyid_help_option'>help_option</span>
|
1461
|
+
<span class='kw'>end</span>
|
1462
|
+
|
1463
|
+
<span class='comment'># Reads and optionally sets the version of this application.
|
1464
|
+
</span> <span class='comment'>#
|
1465
|
+
</span> <span class='comment'># @param value [String|nil] The new version of this application.
|
1466
|
+
</span> <span class='comment'># @return [String|nil] The version of this application.
|
1467
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_version'>version</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
1468
|
+
<span class='ivar'>@version</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span> <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
1469
|
+
<span class='ivar'>@version</span>
|
1470
|
+
<span class='kw'>end</span>
|
1471
|
+
|
1472
|
+
<span class='comment'># Executes this application.
|
1473
|
+
</span> <span class='comment'>#
|
1474
|
+
</span> <span class='comment'># @param args [Array] The command line to pass to this application. Defaults to `ARGV`.
|
1475
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
1476
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span> <span class='op'>||</span> <span class='const'>ARGV</span><span class='rparen'>)</span>
|
1477
|
+
<span class='kw'>end</span>
|
1478
|
+
|
1479
|
+
<span class='comment'># Adds a help command and a help option to this application.
|
1480
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_help_option'>help_option</span>
|
1481
|
+
<span class='id identifier rubyid_command'>command</span><span class='lparen'>(</span><span class='symbol'>:help</span><span class='comma'>,</span> <span class='label'>description:</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_command_description'>help_command_description</span><span class='rparen'>)</span> <span class='kw'>do</span>
|
1482
|
+
<span class='id identifier rubyid_action'>action</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_command'>command</span><span class='op'>|</span> <span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_command_help'>command_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
1483
|
+
<span class='kw'>end</span>
|
1484
|
+
|
1485
|
+
<span class='id identifier rubyid_option'>option</span><span class='lparen'>(</span><span class='symbol'>:help</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_option_short_form'>help_option_short_form</span><span class='comma'>,</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_option_long_form'>help_option_long_form</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='label'>help:</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_message'>help_message</span><span class='rparen'>)</span><span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_application'>application</span><span class='comma'>,</span> <span class='id identifier rubyid__'>_</span><span class='op'>|</span> <span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_show_help'>show_help</span> <span class='rbrace'>}</span>
|
1486
|
+
<span class='kw'>end</span>
|
1487
|
+
|
1488
|
+
<span class='comment'># The name of the current executable.
|
1489
|
+
</span> <span class='comment'>#
|
1490
|
+
</span> <span class='comment'># @return [String] The name of the current executable.
|
1491
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_executable_name'>executable_name</span>
|
1492
|
+
<span class='gvar'>$0</span>
|
1493
|
+
<span class='kw'>end</span>
|
1494
|
+
|
1495
|
+
<span class='comment'># Shows a help about a command.
|
1496
|
+
</span> <span class='comment'>#
|
1497
|
+
</span> <span class='comment'># @param command [Command] The command to show help for.
|
1498
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_command_help'>command_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span>
|
1499
|
+
<span class='id identifier rubyid_fetch_commands_for_help'>fetch_commands_for_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_arg'>arg</span><span class='op'>|</span>
|
1500
|
+
<span class='comment'># Find the command across
|
1501
|
+
</span> <span class='id identifier rubyid_next_command'>next_command</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Parser</span><span class='period'>.</span><span class='id identifier rubyid_find_command'>find_command</span><span class='lparen'>(</span><span class='id identifier rubyid_arg'>arg</span><span class='comma'>,</span> <span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
1502
|
+
|
1503
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_next_command'>next_command</span> <span class='kw'>then</span>
|
1504
|
+
<span class='id identifier rubyid_command'>command</span> <span class='op'>=</span> <span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_commands'>commands</span><span class='lbracket'>[</span><span class='id identifier rubyid_next_command'>next_command</span><span class='lbracket'>[</span><span class='symbol'>:name</span><span class='rbracket'>]</span><span class='rbracket'>]</span>
|
1505
|
+
<span class='kw'>else</span>
|
1506
|
+
<span class='kw'>break</span>
|
1507
|
+
<span class='kw'>end</span>
|
1508
|
+
<span class='kw'>end</span>
|
1509
|
+
|
1510
|
+
<span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_show_help'>show_help</span>
|
1511
|
+
<span class='kw'>end</span>
|
1512
|
+
|
1513
|
+
<span class='comment'># Runs a command into the shell.
|
1514
|
+
</span> <span class='comment'>#
|
1515
|
+
</span> <span class='comment'># @param command [String] The string to run.
|
1516
|
+
</span> <span class='comment'># @param message [String] A message to show before running.
|
1517
|
+
</span> <span class='comment'># @param show_exit [Boolean] If show the exit status.
|
1518
|
+
</span> <span class='comment'># @param fatal [Boolean] If quit in case of fatal errors.
|
1519
|
+
</span> <span class='comment'># @return [Hash] An hash with `status` and `output` keys.
|
1520
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_run'>run</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_show_exit'>show_exit</span> <span class='op'>=</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='id identifier rubyid_fatal'>fatal</span> <span class='op'>=</span> <span class='kw'>true</span><span class='rparen'>)</span>
|
1521
|
+
<span class='ivar'>@shell</span><span class='period'>.</span><span class='id identifier rubyid_run'>run</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>!</span><span class='ivar'>@skip_commands</span><span class='comma'>,</span> <span class='id identifier rubyid_show_exit'>show_exit</span><span class='comma'>,</span> <span class='ivar'>@output_commands</span><span class='comma'>,</span> <span class='ivar'>@show_commands</span><span class='comma'>,</span> <span class='id identifier rubyid_fatal'>fatal</span><span class='rparen'>)</span>
|
1522
|
+
<span class='kw'>end</span>
|
1523
|
+
|
1524
|
+
<span class='id identifier rubyid_private'>private</span>
|
1525
|
+
<span class='comment'># Setup options for application creation.
|
1526
|
+
</span> <span class='comment'>#
|
1527
|
+
</span> <span class='comment'># @param options [Hash] The options to setups.
|
1528
|
+
</span> <span class='comment'># @return [Array] If to run the application, the arguments and the specified options.
|
1529
|
+
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_setup_application_option'>setup_application_option</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
|
1530
|
+
<span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='label'>name:</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_localize_on_locale'>localize_on_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='symbol'>:default_application_name</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='label'>parent:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>application:</span> <span class='kw'>nil</span><span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_ensure_hash'>ensure_hash</span><span class='rparen'>)</span>
|
1531
|
+
<span class='id identifier rubyid_run'>run</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:run</span><span class='rparen'>)</span>
|
1532
|
+
<span class='lbracket'>[</span><span class='lparen'>(</span><span class='op'>!</span><span class='id identifier rubyid_run'>run</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> <span class='op'>?</span> <span class='id identifier rubyid_run'>run</span> <span class='op'>:</span> <span class='kw'>true</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_boolean'>to_boolean</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:__args__</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='rbracket'>]</span>
|
1533
|
+
<span class='kw'>end</span>
|
1534
|
+
|
1535
|
+
<span class='comment'># Create the application.
|
1536
|
+
</span> <span class='comment'>#
|
1537
|
+
</span> <span class='comment'># @param run [Boolean ]If to run the application.
|
1538
|
+
</span> <span class='comment'># @param args [Hash] The arguments to use for running.
|
1539
|
+
</span> <span class='comment'># @param options [Hash] The options of the application.
|
1540
|
+
</span> <span class='comment'># @return [Application] The new application.
|
1541
|
+
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create_application'>create_application</span><span class='lparen'>(</span><span class='id identifier rubyid_run'>run</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1542
|
+
<span class='id identifier rubyid_application'>application</span> <span class='op'>=</span> <span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1543
|
+
<span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_application'>application</span> <span class='op'>&&</span> <span class='id identifier rubyid_run'>run</span>
|
1544
|
+
<span class='id identifier rubyid_application'>application</span>
|
1545
|
+
<span class='kw'>end</span>
|
1546
|
+
|
1547
|
+
<span class='comment'># Fetch a command list for showing help.
|
1548
|
+
</span> <span class='comment'>#
|
1549
|
+
</span> <span class='comment'># @param command [Command] The command to show help for.
|
1550
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_fetch_commands_for_help'>fetch_commands_for_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span>
|
1551
|
+
<span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_c'>c</span><span class='op'>|</span> <span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_split'>split</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>:</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:strip</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_select'>select</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:present?</span><span class='rparen'>)</span>
|
1552
|
+
<span class='kw'>end</span>
|
1553
|
+
<span class='kw'>end</span></pre>
|
1554
|
+
</td>
|
1555
|
+
</tr>
|
1556
|
+
</table>
|
1557
|
+
</div>
|
1558
|
+
|
1559
|
+
|
1560
|
+
<span id="show_commands=-instance_method"></span>
|
1561
|
+
<div class="method_details ">
|
1562
|
+
<h3 class="signature " id="show_commands-instance_method">
|
1563
|
+
|
1564
|
+
- (<tt>Boolean</tt>) <strong>show_commands</strong>
|
1565
|
+
|
1566
|
+
|
1567
|
+
|
1568
|
+
|
1569
|
+
|
1570
|
+
</h3><div class="docstring">
|
1571
|
+
<div class="discussion">
|
1572
|
+
<p>If to show command lines run via <span class='object_link'><a href="#run-instance_method" title="Mamertes::Application#run (method)">#run</a></span>.</p>
|
1573
|
+
|
1574
|
+
|
1575
|
+
</div>
|
1576
|
+
</div>
|
1577
|
+
<div class="tags">
|
1578
|
+
|
1579
|
+
<p class="tag_title">Returns:</p>
|
1580
|
+
<ul class="return">
|
1581
|
+
|
1582
|
+
<li>
|
1583
|
+
|
1584
|
+
|
1585
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
1586
|
+
|
1587
|
+
|
1588
|
+
|
1589
|
+
—
|
1590
|
+
<div class='inline'><p>If to show command lines run via <span class='object_link'><a href="#run-instance_method" title="Mamertes::Application#run (method)">#run</a></span>.</p>
|
1591
|
+
</div>
|
1592
|
+
|
1593
|
+
</li>
|
1594
|
+
|
1595
|
+
</ul>
|
1596
|
+
|
1597
|
+
</div><table class="source_code">
|
1598
|
+
<tr>
|
1599
|
+
<td>
|
1600
|
+
<pre class="lines">
|
1601
|
+
|
1602
|
+
|
1603
|
+
72
|
1604
|
+
73
|
1605
|
+
74
|
1606
|
+
75
|
1607
|
+
76
|
1608
|
+
77
|
1609
|
+
78
|
1610
|
+
79
|
1611
|
+
80
|
1612
|
+
81
|
1613
|
+
82
|
1614
|
+
83
|
1615
|
+
84
|
1616
|
+
85
|
1617
|
+
86
|
1618
|
+
87
|
1619
|
+
88
|
1620
|
+
89
|
1621
|
+
90
|
1622
|
+
91
|
1623
|
+
92
|
1624
|
+
93
|
1625
|
+
94
|
1626
|
+
95
|
1627
|
+
96
|
1628
|
+
97
|
1629
|
+
98
|
1630
|
+
99
|
1631
|
+
100
|
1632
|
+
101
|
1633
|
+
102
|
1634
|
+
103
|
1635
|
+
104
|
1636
|
+
105
|
1637
|
+
106
|
1638
|
+
107
|
1639
|
+
108
|
1640
|
+
109
|
1641
|
+
110
|
1642
|
+
111
|
1643
|
+
112
|
1644
|
+
113
|
1645
|
+
114
|
1646
|
+
115
|
1647
|
+
116
|
1648
|
+
117
|
1649
|
+
118
|
1650
|
+
119
|
1651
|
+
120
|
1652
|
+
121
|
1653
|
+
122
|
1654
|
+
123
|
1655
|
+
124
|
1656
|
+
125
|
1657
|
+
126
|
1658
|
+
127
|
1659
|
+
128
|
1660
|
+
129
|
1661
|
+
130
|
1662
|
+
131
|
1663
|
+
132
|
1664
|
+
133
|
1665
|
+
134
|
1666
|
+
135
|
1667
|
+
136
|
1668
|
+
137
|
1669
|
+
138
|
1670
|
+
139
|
1671
|
+
140
|
1672
|
+
141
|
1673
|
+
142
|
1674
|
+
143
|
1675
|
+
144
|
1676
|
+
145
|
1677
|
+
146
|
1678
|
+
147
|
1679
|
+
148
|
1680
|
+
149
|
1681
|
+
150
|
1682
|
+
151
|
1683
|
+
152
|
1684
|
+
153
|
1685
|
+
154
|
1686
|
+
155
|
1687
|
+
156
|
1688
|
+
157
|
1689
|
+
158
|
1690
|
+
159
|
1691
|
+
160
|
1692
|
+
161
|
1693
|
+
162
|
1694
|
+
163
|
1695
|
+
164
|
1696
|
+
165
|
1697
|
+
166
|
1698
|
+
167
|
1699
|
+
168
|
1700
|
+
169
|
1701
|
+
170
|
1702
|
+
171
|
1703
|
+
172
|
1704
|
+
173
|
1705
|
+
174
|
1706
|
+
175
|
1707
|
+
176
|
1708
|
+
177
|
1709
|
+
178
|
1710
|
+
179
|
1711
|
+
180
|
1712
|
+
181
|
1713
|
+
182
|
1714
|
+
183
|
1715
|
+
184
|
1716
|
+
185
|
1717
|
+
186
|
1718
|
+
187
|
1719
|
+
188
|
1720
|
+
189
|
1721
|
+
190
|
1722
|
+
191
|
1723
|
+
192
|
1724
|
+
193
|
1725
|
+
194
|
1726
|
+
195
|
1727
|
+
196
|
1728
|
+
197
|
1729
|
+
198
|
1730
|
+
199
|
1731
|
+
200
|
1732
|
+
201
|
1733
|
+
202
|
1734
|
+
203
|
1735
|
+
204
|
1736
|
+
205</pre>
|
1737
|
+
</td>
|
1738
|
+
<td>
|
1739
|
+
<pre class="code"><span class="info file"># File 'lib/mamertes/application.rb', line 72</span>
|
1740
|
+
|
1741
|
+
<span class='kw'>class</span> <span class='const'>Application</span> <span class='op'><</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Command</span>
|
1742
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:version</span>
|
1743
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:shell</span>
|
1744
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:console</span>
|
1745
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:skip_commands</span>
|
1746
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:show_commands</span>
|
1747
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:output_commands</span>
|
1748
|
+
|
1749
|
+
<span class='comment'># Initializes a new Mamertes application.
|
1750
|
+
</span> <span class='comment'>#
|
1751
|
+
</span> <span class='comment'># In options, you can override the command line arguments with `:__args__`, and you can skip execution by specifying `run: false`.
|
1752
|
+
</span> <span class='comment'>#
|
1753
|
+
</span> <span class='comment'># @see Command#setup_with
|
1754
|
+
</span> <span class='comment'>#
|
1755
|
+
</span> <span class='comment'># @param options [Hash] The settings to initialize the application with.
|
1756
|
+
</span> <span class='comment'># @return [Application] The created application.
|
1757
|
+
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1758
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Error</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Application</span><span class='comma'>,</span> <span class='symbol'>:missing_block</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_localize_on_locale'>localize_on_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='symbol'>:missing_app_block</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_block_given?'>block_given?</span>
|
1759
|
+
<span class='id identifier rubyid_run'>run</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='id identifier rubyid_setup_application_option'>setup_application_option</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
|
1760
|
+
|
1761
|
+
<span class='kw'>begin</span>
|
1762
|
+
<span class='id identifier rubyid_create_application'>create_application</span><span class='lparen'>(</span><span class='id identifier rubyid_run'>run</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1763
|
+
<span class='kw'>rescue</span> <span class='op'>=></span> <span class='id identifier rubyid_e'>e</span>
|
1764
|
+
<span class='const'>Kernel</span><span class='period'>.</span><span class='id identifier rubyid_puts'>puts</span><span class='lparen'>(</span><span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span>
|
1765
|
+
<span class='const'>Kernel</span><span class='period'>.</span><span class='id identifier rubyid_exit'>exit</span><span class='lparen'>(</span><span class='int'>1</span><span class='rparen'>)</span>
|
1766
|
+
<span class='kw'>end</span>
|
1767
|
+
<span class='kw'>end</span>
|
1768
|
+
|
1769
|
+
<span class='comment'># Creates a new application.
|
1770
|
+
</span> <span class='comment'>#
|
1771
|
+
</span> <span class='comment'># @param options [Hash] The settings to initialize the application with.
|
1772
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1773
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1774
|
+
|
1775
|
+
<span class='ivar'>@shell</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Bovem</span><span class='op'>::</span><span class='const'>Shell</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span>
|
1776
|
+
<span class='ivar'>@console</span> <span class='op'>=</span> <span class='ivar'>@shell</span><span class='period'>.</span><span class='id identifier rubyid_console'>console</span>
|
1777
|
+
<span class='ivar'>@skip_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
1778
|
+
<span class='ivar'>@show_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
1779
|
+
<span class='ivar'>@output_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
1780
|
+
|
1781
|
+
<span class='id identifier rubyid_help_option'>help_option</span>
|
1782
|
+
<span class='kw'>end</span>
|
1783
|
+
|
1784
|
+
<span class='comment'># Reads and optionally sets the version of this application.
|
1785
|
+
</span> <span class='comment'>#
|
1786
|
+
</span> <span class='comment'># @param value [String|nil] The new version of this application.
|
1787
|
+
</span> <span class='comment'># @return [String|nil] The version of this application.
|
1788
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_version'>version</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
1789
|
+
<span class='ivar'>@version</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span> <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
1790
|
+
<span class='ivar'>@version</span>
|
1791
|
+
<span class='kw'>end</span>
|
1792
|
+
|
1793
|
+
<span class='comment'># Executes this application.
|
1794
|
+
</span> <span class='comment'>#
|
1795
|
+
</span> <span class='comment'># @param args [Array] The command line to pass to this application. Defaults to `ARGV`.
|
1796
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
1797
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span> <span class='op'>||</span> <span class='const'>ARGV</span><span class='rparen'>)</span>
|
1798
|
+
<span class='kw'>end</span>
|
1799
|
+
|
1800
|
+
<span class='comment'># Adds a help command and a help option to this application.
|
1801
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_help_option'>help_option</span>
|
1802
|
+
<span class='id identifier rubyid_command'>command</span><span class='lparen'>(</span><span class='symbol'>:help</span><span class='comma'>,</span> <span class='label'>description:</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_command_description'>help_command_description</span><span class='rparen'>)</span> <span class='kw'>do</span>
|
1803
|
+
<span class='id identifier rubyid_action'>action</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_command'>command</span><span class='op'>|</span> <span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_command_help'>command_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
1804
|
+
<span class='kw'>end</span>
|
1805
|
+
|
1806
|
+
<span class='id identifier rubyid_option'>option</span><span class='lparen'>(</span><span class='symbol'>:help</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_option_short_form'>help_option_short_form</span><span class='comma'>,</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_option_long_form'>help_option_long_form</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='label'>help:</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_message'>help_message</span><span class='rparen'>)</span><span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_application'>application</span><span class='comma'>,</span> <span class='id identifier rubyid__'>_</span><span class='op'>|</span> <span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_show_help'>show_help</span> <span class='rbrace'>}</span>
|
1807
|
+
<span class='kw'>end</span>
|
1808
|
+
|
1809
|
+
<span class='comment'># The name of the current executable.
|
1810
|
+
</span> <span class='comment'>#
|
1811
|
+
</span> <span class='comment'># @return [String] The name of the current executable.
|
1812
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_executable_name'>executable_name</span>
|
1813
|
+
<span class='gvar'>$0</span>
|
1814
|
+
<span class='kw'>end</span>
|
1815
|
+
|
1816
|
+
<span class='comment'># Shows a help about a command.
|
1817
|
+
</span> <span class='comment'>#
|
1818
|
+
</span> <span class='comment'># @param command [Command] The command to show help for.
|
1819
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_command_help'>command_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span>
|
1820
|
+
<span class='id identifier rubyid_fetch_commands_for_help'>fetch_commands_for_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_arg'>arg</span><span class='op'>|</span>
|
1821
|
+
<span class='comment'># Find the command across
|
1822
|
+
</span> <span class='id identifier rubyid_next_command'>next_command</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Parser</span><span class='period'>.</span><span class='id identifier rubyid_find_command'>find_command</span><span class='lparen'>(</span><span class='id identifier rubyid_arg'>arg</span><span class='comma'>,</span> <span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
1823
|
+
|
1824
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_next_command'>next_command</span> <span class='kw'>then</span>
|
1825
|
+
<span class='id identifier rubyid_command'>command</span> <span class='op'>=</span> <span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_commands'>commands</span><span class='lbracket'>[</span><span class='id identifier rubyid_next_command'>next_command</span><span class='lbracket'>[</span><span class='symbol'>:name</span><span class='rbracket'>]</span><span class='rbracket'>]</span>
|
1826
|
+
<span class='kw'>else</span>
|
1827
|
+
<span class='kw'>break</span>
|
1828
|
+
<span class='kw'>end</span>
|
1829
|
+
<span class='kw'>end</span>
|
1830
|
+
|
1831
|
+
<span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_show_help'>show_help</span>
|
1832
|
+
<span class='kw'>end</span>
|
1833
|
+
|
1834
|
+
<span class='comment'># Runs a command into the shell.
|
1835
|
+
</span> <span class='comment'>#
|
1836
|
+
</span> <span class='comment'># @param command [String] The string to run.
|
1837
|
+
</span> <span class='comment'># @param message [String] A message to show before running.
|
1838
|
+
</span> <span class='comment'># @param show_exit [Boolean] If show the exit status.
|
1839
|
+
</span> <span class='comment'># @param fatal [Boolean] If quit in case of fatal errors.
|
1840
|
+
</span> <span class='comment'># @return [Hash] An hash with `status` and `output` keys.
|
1841
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_run'>run</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_show_exit'>show_exit</span> <span class='op'>=</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='id identifier rubyid_fatal'>fatal</span> <span class='op'>=</span> <span class='kw'>true</span><span class='rparen'>)</span>
|
1842
|
+
<span class='ivar'>@shell</span><span class='period'>.</span><span class='id identifier rubyid_run'>run</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>!</span><span class='ivar'>@skip_commands</span><span class='comma'>,</span> <span class='id identifier rubyid_show_exit'>show_exit</span><span class='comma'>,</span> <span class='ivar'>@output_commands</span><span class='comma'>,</span> <span class='ivar'>@show_commands</span><span class='comma'>,</span> <span class='id identifier rubyid_fatal'>fatal</span><span class='rparen'>)</span>
|
1843
|
+
<span class='kw'>end</span>
|
1844
|
+
|
1845
|
+
<span class='id identifier rubyid_private'>private</span>
|
1846
|
+
<span class='comment'># Setup options for application creation.
|
1847
|
+
</span> <span class='comment'>#
|
1848
|
+
</span> <span class='comment'># @param options [Hash] The options to setups.
|
1849
|
+
</span> <span class='comment'># @return [Array] If to run the application, the arguments and the specified options.
|
1850
|
+
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_setup_application_option'>setup_application_option</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
|
1851
|
+
<span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='label'>name:</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_localize_on_locale'>localize_on_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='symbol'>:default_application_name</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='label'>parent:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>application:</span> <span class='kw'>nil</span><span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_ensure_hash'>ensure_hash</span><span class='rparen'>)</span>
|
1852
|
+
<span class='id identifier rubyid_run'>run</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:run</span><span class='rparen'>)</span>
|
1853
|
+
<span class='lbracket'>[</span><span class='lparen'>(</span><span class='op'>!</span><span class='id identifier rubyid_run'>run</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> <span class='op'>?</span> <span class='id identifier rubyid_run'>run</span> <span class='op'>:</span> <span class='kw'>true</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_boolean'>to_boolean</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:__args__</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='rbracket'>]</span>
|
1854
|
+
<span class='kw'>end</span>
|
1855
|
+
|
1856
|
+
<span class='comment'># Create the application.
|
1857
|
+
</span> <span class='comment'>#
|
1858
|
+
</span> <span class='comment'># @param run [Boolean ]If to run the application.
|
1859
|
+
</span> <span class='comment'># @param args [Hash] The arguments to use for running.
|
1860
|
+
</span> <span class='comment'># @param options [Hash] The options of the application.
|
1861
|
+
</span> <span class='comment'># @return [Application] The new application.
|
1862
|
+
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create_application'>create_application</span><span class='lparen'>(</span><span class='id identifier rubyid_run'>run</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1863
|
+
<span class='id identifier rubyid_application'>application</span> <span class='op'>=</span> <span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1864
|
+
<span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_application'>application</span> <span class='op'>&&</span> <span class='id identifier rubyid_run'>run</span>
|
1865
|
+
<span class='id identifier rubyid_application'>application</span>
|
1866
|
+
<span class='kw'>end</span>
|
1867
|
+
|
1868
|
+
<span class='comment'># Fetch a command list for showing help.
|
1869
|
+
</span> <span class='comment'>#
|
1870
|
+
</span> <span class='comment'># @param command [Command] The command to show help for.
|
1871
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_fetch_commands_for_help'>fetch_commands_for_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span>
|
1872
|
+
<span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_c'>c</span><span class='op'>|</span> <span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_split'>split</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>:</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:strip</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_select'>select</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:present?</span><span class='rparen'>)</span>
|
1873
|
+
<span class='kw'>end</span>
|
1874
|
+
<span class='kw'>end</span></pre>
|
1875
|
+
</td>
|
1876
|
+
</tr>
|
1877
|
+
</table>
|
1878
|
+
</div>
|
1879
|
+
|
1880
|
+
|
1881
|
+
<span id="skip_commands=-instance_method"></span>
|
1882
|
+
<div class="method_details ">
|
1883
|
+
<h3 class="signature " id="skip_commands-instance_method">
|
1884
|
+
|
1885
|
+
- (<tt>Boolean</tt>) <strong>skip_commands</strong>
|
1886
|
+
|
1887
|
+
|
1888
|
+
|
1889
|
+
|
1890
|
+
|
1891
|
+
</h3><div class="docstring">
|
1892
|
+
<div class="discussion">
|
1893
|
+
<p>If to skip commands run via <span class='object_link'><a href="#run-instance_method" title="Mamertes::Application#run (method)">#run</a></span>.</p>
|
1894
|
+
|
1895
|
+
|
1896
|
+
</div>
|
1897
|
+
</div>
|
1898
|
+
<div class="tags">
|
1899
|
+
|
1900
|
+
<p class="tag_title">Returns:</p>
|
1901
|
+
<ul class="return">
|
1902
|
+
|
1903
|
+
<li>
|
1904
|
+
|
1905
|
+
|
1906
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
1907
|
+
|
1908
|
+
|
1909
|
+
|
1910
|
+
—
|
1911
|
+
<div class='inline'><p>If to skip commands run via <span class='object_link'><a href="#run-instance_method" title="Mamertes::Application#run (method)">#run</a></span>.</p>
|
1912
|
+
</div>
|
1913
|
+
|
1914
|
+
</li>
|
1915
|
+
|
1916
|
+
</ul>
|
1917
|
+
|
1918
|
+
</div><table class="source_code">
|
1919
|
+
<tr>
|
1920
|
+
<td>
|
1921
|
+
<pre class="lines">
|
1922
|
+
|
1923
|
+
|
1924
|
+
72
|
1925
|
+
73
|
1926
|
+
74
|
1927
|
+
75
|
1928
|
+
76
|
1929
|
+
77
|
1930
|
+
78
|
1931
|
+
79
|
1932
|
+
80
|
1933
|
+
81
|
1934
|
+
82
|
1935
|
+
83
|
1936
|
+
84
|
1937
|
+
85
|
1938
|
+
86
|
1939
|
+
87
|
1940
|
+
88
|
1941
|
+
89
|
1942
|
+
90
|
1943
|
+
91
|
1944
|
+
92
|
1945
|
+
93
|
1946
|
+
94
|
1947
|
+
95
|
1948
|
+
96
|
1949
|
+
97
|
1950
|
+
98
|
1951
|
+
99
|
1952
|
+
100
|
1953
|
+
101
|
1954
|
+
102
|
1955
|
+
103
|
1956
|
+
104
|
1957
|
+
105
|
1958
|
+
106
|
1959
|
+
107
|
1960
|
+
108
|
1961
|
+
109
|
1962
|
+
110
|
1963
|
+
111
|
1964
|
+
112
|
1965
|
+
113
|
1966
|
+
114
|
1967
|
+
115
|
1968
|
+
116
|
1969
|
+
117
|
1970
|
+
118
|
1971
|
+
119
|
1972
|
+
120
|
1973
|
+
121
|
1974
|
+
122
|
1975
|
+
123
|
1976
|
+
124
|
1977
|
+
125
|
1978
|
+
126
|
1979
|
+
127
|
1980
|
+
128
|
1981
|
+
129
|
1982
|
+
130
|
1983
|
+
131
|
1984
|
+
132
|
1985
|
+
133
|
1986
|
+
134
|
1987
|
+
135
|
1988
|
+
136
|
1989
|
+
137
|
1990
|
+
138
|
1991
|
+
139
|
1992
|
+
140
|
1993
|
+
141
|
1994
|
+
142
|
1995
|
+
143
|
1996
|
+
144
|
1997
|
+
145
|
1998
|
+
146
|
1999
|
+
147
|
2000
|
+
148
|
2001
|
+
149
|
2002
|
+
150
|
2003
|
+
151
|
2004
|
+
152
|
2005
|
+
153
|
2006
|
+
154
|
2007
|
+
155
|
2008
|
+
156
|
2009
|
+
157
|
2010
|
+
158
|
2011
|
+
159
|
2012
|
+
160
|
2013
|
+
161
|
2014
|
+
162
|
2015
|
+
163
|
2016
|
+
164
|
2017
|
+
165
|
2018
|
+
166
|
2019
|
+
167
|
2020
|
+
168
|
2021
|
+
169
|
2022
|
+
170
|
2023
|
+
171
|
2024
|
+
172
|
2025
|
+
173
|
2026
|
+
174
|
2027
|
+
175
|
2028
|
+
176
|
2029
|
+
177
|
2030
|
+
178
|
2031
|
+
179
|
2032
|
+
180
|
2033
|
+
181
|
2034
|
+
182
|
2035
|
+
183
|
2036
|
+
184
|
2037
|
+
185
|
2038
|
+
186
|
2039
|
+
187
|
2040
|
+
188
|
2041
|
+
189
|
2042
|
+
190
|
2043
|
+
191
|
2044
|
+
192
|
2045
|
+
193
|
2046
|
+
194
|
2047
|
+
195
|
2048
|
+
196
|
2049
|
+
197
|
2050
|
+
198
|
2051
|
+
199
|
2052
|
+
200
|
2053
|
+
201
|
2054
|
+
202
|
2055
|
+
203
|
2056
|
+
204
|
2057
|
+
205</pre>
|
2058
|
+
</td>
|
2059
|
+
<td>
|
2060
|
+
<pre class="code"><span class="info file"># File 'lib/mamertes/application.rb', line 72</span>
|
2061
|
+
|
2062
|
+
<span class='kw'>class</span> <span class='const'>Application</span> <span class='op'><</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Command</span>
|
2063
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:version</span>
|
2064
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:shell</span>
|
2065
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:console</span>
|
2066
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:skip_commands</span>
|
2067
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:show_commands</span>
|
2068
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:output_commands</span>
|
2069
|
+
|
2070
|
+
<span class='comment'># Initializes a new Mamertes application.
|
2071
|
+
</span> <span class='comment'>#
|
2072
|
+
</span> <span class='comment'># In options, you can override the command line arguments with `:__args__`, and you can skip execution by specifying `run: false`.
|
2073
|
+
</span> <span class='comment'>#
|
2074
|
+
</span> <span class='comment'># @see Command#setup_with
|
2075
|
+
</span> <span class='comment'>#
|
2076
|
+
</span> <span class='comment'># @param options [Hash] The settings to initialize the application with.
|
2077
|
+
</span> <span class='comment'># @return [Application] The created application.
|
2078
|
+
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2079
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Error</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Application</span><span class='comma'>,</span> <span class='symbol'>:missing_block</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_localize_on_locale'>localize_on_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='symbol'>:missing_app_block</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_block_given?'>block_given?</span>
|
2080
|
+
<span class='id identifier rubyid_run'>run</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='id identifier rubyid_setup_application_option'>setup_application_option</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
|
2081
|
+
|
2082
|
+
<span class='kw'>begin</span>
|
2083
|
+
<span class='id identifier rubyid_create_application'>create_application</span><span class='lparen'>(</span><span class='id identifier rubyid_run'>run</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2084
|
+
<span class='kw'>rescue</span> <span class='op'>=></span> <span class='id identifier rubyid_e'>e</span>
|
2085
|
+
<span class='const'>Kernel</span><span class='period'>.</span><span class='id identifier rubyid_puts'>puts</span><span class='lparen'>(</span><span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span>
|
2086
|
+
<span class='const'>Kernel</span><span class='period'>.</span><span class='id identifier rubyid_exit'>exit</span><span class='lparen'>(</span><span class='int'>1</span><span class='rparen'>)</span>
|
2087
|
+
<span class='kw'>end</span>
|
2088
|
+
<span class='kw'>end</span>
|
2089
|
+
|
2090
|
+
<span class='comment'># Creates a new application.
|
2091
|
+
</span> <span class='comment'>#
|
2092
|
+
</span> <span class='comment'># @param options [Hash] The settings to initialize the application with.
|
2093
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2094
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2095
|
+
|
2096
|
+
<span class='ivar'>@shell</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Bovem</span><span class='op'>::</span><span class='const'>Shell</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span>
|
2097
|
+
<span class='ivar'>@console</span> <span class='op'>=</span> <span class='ivar'>@shell</span><span class='period'>.</span><span class='id identifier rubyid_console'>console</span>
|
2098
|
+
<span class='ivar'>@skip_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
2099
|
+
<span class='ivar'>@show_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
2100
|
+
<span class='ivar'>@output_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
2101
|
+
|
2102
|
+
<span class='id identifier rubyid_help_option'>help_option</span>
|
2103
|
+
<span class='kw'>end</span>
|
2104
|
+
|
2105
|
+
<span class='comment'># Reads and optionally sets the version of this application.
|
2106
|
+
</span> <span class='comment'>#
|
2107
|
+
</span> <span class='comment'># @param value [String|nil] The new version of this application.
|
2108
|
+
</span> <span class='comment'># @return [String|nil] The version of this application.
|
2109
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_version'>version</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
2110
|
+
<span class='ivar'>@version</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span> <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
2111
|
+
<span class='ivar'>@version</span>
|
2112
|
+
<span class='kw'>end</span>
|
2113
|
+
|
2114
|
+
<span class='comment'># Executes this application.
|
2115
|
+
</span> <span class='comment'>#
|
2116
|
+
</span> <span class='comment'># @param args [Array] The command line to pass to this application. Defaults to `ARGV`.
|
2117
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
2118
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span> <span class='op'>||</span> <span class='const'>ARGV</span><span class='rparen'>)</span>
|
2119
|
+
<span class='kw'>end</span>
|
2120
|
+
|
2121
|
+
<span class='comment'># Adds a help command and a help option to this application.
|
2122
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_help_option'>help_option</span>
|
2123
|
+
<span class='id identifier rubyid_command'>command</span><span class='lparen'>(</span><span class='symbol'>:help</span><span class='comma'>,</span> <span class='label'>description:</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_command_description'>help_command_description</span><span class='rparen'>)</span> <span class='kw'>do</span>
|
2124
|
+
<span class='id identifier rubyid_action'>action</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_command'>command</span><span class='op'>|</span> <span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_command_help'>command_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
2125
|
+
<span class='kw'>end</span>
|
2126
|
+
|
2127
|
+
<span class='id identifier rubyid_option'>option</span><span class='lparen'>(</span><span class='symbol'>:help</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_option_short_form'>help_option_short_form</span><span class='comma'>,</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_option_long_form'>help_option_long_form</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='label'>help:</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_message'>help_message</span><span class='rparen'>)</span><span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_application'>application</span><span class='comma'>,</span> <span class='id identifier rubyid__'>_</span><span class='op'>|</span> <span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_show_help'>show_help</span> <span class='rbrace'>}</span>
|
2128
|
+
<span class='kw'>end</span>
|
2129
|
+
|
2130
|
+
<span class='comment'># The name of the current executable.
|
2131
|
+
</span> <span class='comment'>#
|
2132
|
+
</span> <span class='comment'># @return [String] The name of the current executable.
|
2133
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_executable_name'>executable_name</span>
|
2134
|
+
<span class='gvar'>$0</span>
|
2135
|
+
<span class='kw'>end</span>
|
2136
|
+
|
2137
|
+
<span class='comment'># Shows a help about a command.
|
2138
|
+
</span> <span class='comment'>#
|
2139
|
+
</span> <span class='comment'># @param command [Command] The command to show help for.
|
2140
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_command_help'>command_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span>
|
2141
|
+
<span class='id identifier rubyid_fetch_commands_for_help'>fetch_commands_for_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_arg'>arg</span><span class='op'>|</span>
|
2142
|
+
<span class='comment'># Find the command across
|
2143
|
+
</span> <span class='id identifier rubyid_next_command'>next_command</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Parser</span><span class='period'>.</span><span class='id identifier rubyid_find_command'>find_command</span><span class='lparen'>(</span><span class='id identifier rubyid_arg'>arg</span><span class='comma'>,</span> <span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
2144
|
+
|
2145
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_next_command'>next_command</span> <span class='kw'>then</span>
|
2146
|
+
<span class='id identifier rubyid_command'>command</span> <span class='op'>=</span> <span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_commands'>commands</span><span class='lbracket'>[</span><span class='id identifier rubyid_next_command'>next_command</span><span class='lbracket'>[</span><span class='symbol'>:name</span><span class='rbracket'>]</span><span class='rbracket'>]</span>
|
2147
|
+
<span class='kw'>else</span>
|
2148
|
+
<span class='kw'>break</span>
|
2149
|
+
<span class='kw'>end</span>
|
2150
|
+
<span class='kw'>end</span>
|
2151
|
+
|
2152
|
+
<span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_show_help'>show_help</span>
|
2153
|
+
<span class='kw'>end</span>
|
2154
|
+
|
2155
|
+
<span class='comment'># Runs a command into the shell.
|
2156
|
+
</span> <span class='comment'>#
|
2157
|
+
</span> <span class='comment'># @param command [String] The string to run.
|
2158
|
+
</span> <span class='comment'># @param message [String] A message to show before running.
|
2159
|
+
</span> <span class='comment'># @param show_exit [Boolean] If show the exit status.
|
2160
|
+
</span> <span class='comment'># @param fatal [Boolean] If quit in case of fatal errors.
|
2161
|
+
</span> <span class='comment'># @return [Hash] An hash with `status` and `output` keys.
|
2162
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_run'>run</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_show_exit'>show_exit</span> <span class='op'>=</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='id identifier rubyid_fatal'>fatal</span> <span class='op'>=</span> <span class='kw'>true</span><span class='rparen'>)</span>
|
2163
|
+
<span class='ivar'>@shell</span><span class='period'>.</span><span class='id identifier rubyid_run'>run</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>!</span><span class='ivar'>@skip_commands</span><span class='comma'>,</span> <span class='id identifier rubyid_show_exit'>show_exit</span><span class='comma'>,</span> <span class='ivar'>@output_commands</span><span class='comma'>,</span> <span class='ivar'>@show_commands</span><span class='comma'>,</span> <span class='id identifier rubyid_fatal'>fatal</span><span class='rparen'>)</span>
|
2164
|
+
<span class='kw'>end</span>
|
2165
|
+
|
2166
|
+
<span class='id identifier rubyid_private'>private</span>
|
2167
|
+
<span class='comment'># Setup options for application creation.
|
2168
|
+
</span> <span class='comment'>#
|
2169
|
+
</span> <span class='comment'># @param options [Hash] The options to setups.
|
2170
|
+
</span> <span class='comment'># @return [Array] If to run the application, the arguments and the specified options.
|
2171
|
+
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_setup_application_option'>setup_application_option</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
|
2172
|
+
<span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='label'>name:</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_localize_on_locale'>localize_on_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='symbol'>:default_application_name</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='label'>parent:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>application:</span> <span class='kw'>nil</span><span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_ensure_hash'>ensure_hash</span><span class='rparen'>)</span>
|
2173
|
+
<span class='id identifier rubyid_run'>run</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:run</span><span class='rparen'>)</span>
|
2174
|
+
<span class='lbracket'>[</span><span class='lparen'>(</span><span class='op'>!</span><span class='id identifier rubyid_run'>run</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> <span class='op'>?</span> <span class='id identifier rubyid_run'>run</span> <span class='op'>:</span> <span class='kw'>true</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_boolean'>to_boolean</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:__args__</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='rbracket'>]</span>
|
2175
|
+
<span class='kw'>end</span>
|
2176
|
+
|
2177
|
+
<span class='comment'># Create the application.
|
2178
|
+
</span> <span class='comment'>#
|
2179
|
+
</span> <span class='comment'># @param run [Boolean ]If to run the application.
|
2180
|
+
</span> <span class='comment'># @param args [Hash] The arguments to use for running.
|
2181
|
+
</span> <span class='comment'># @param options [Hash] The options of the application.
|
2182
|
+
</span> <span class='comment'># @return [Application] The new application.
|
2183
|
+
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create_application'>create_application</span><span class='lparen'>(</span><span class='id identifier rubyid_run'>run</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2184
|
+
<span class='id identifier rubyid_application'>application</span> <span class='op'>=</span> <span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2185
|
+
<span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_application'>application</span> <span class='op'>&&</span> <span class='id identifier rubyid_run'>run</span>
|
2186
|
+
<span class='id identifier rubyid_application'>application</span>
|
2187
|
+
<span class='kw'>end</span>
|
2188
|
+
|
2189
|
+
<span class='comment'># Fetch a command list for showing help.
|
2190
|
+
</span> <span class='comment'>#
|
2191
|
+
</span> <span class='comment'># @param command [Command] The command to show help for.
|
2192
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_fetch_commands_for_help'>fetch_commands_for_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span>
|
2193
|
+
<span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_c'>c</span><span class='op'>|</span> <span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_split'>split</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>:</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:strip</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_select'>select</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:present?</span><span class='rparen'>)</span>
|
2194
|
+
<span class='kw'>end</span>
|
2195
|
+
<span class='kw'>end</span></pre>
|
2196
|
+
</td>
|
2197
|
+
</tr>
|
2198
|
+
</table>
|
2199
|
+
</div>
|
2200
|
+
|
2201
|
+
|
2202
|
+
<span id="version=-instance_method"></span>
|
2203
|
+
<div class="method_details ">
|
2204
|
+
<h3 class="signature " id="version-instance_method">
|
2205
|
+
|
2206
|
+
- (<tt>String|nil</tt>) <strong>version</strong>(value = nil)
|
2207
|
+
|
2208
|
+
|
2209
|
+
|
2210
|
+
|
2211
|
+
|
2212
|
+
</h3><div class="docstring">
|
2213
|
+
<div class="discussion">
|
2214
|
+
<p>Reads and optionally sets the version of this application.</p>
|
2215
|
+
|
2216
|
+
|
2217
|
+
</div>
|
2218
|
+
</div>
|
2219
|
+
<div class="tags">
|
2220
|
+
<p class="tag_title">Parameters:</p>
|
2221
|
+
<ul class="param">
|
2222
|
+
|
2223
|
+
<li>
|
2224
|
+
|
2225
|
+
<span class='name'>value</span>
|
2226
|
+
|
2227
|
+
|
2228
|
+
<span class='type'>(<tt>String|nil</tt>)</span>
|
2229
|
+
|
2230
|
+
|
2231
|
+
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
2232
|
+
|
2233
|
+
|
2234
|
+
—
|
2235
|
+
<div class='inline'><p>The new version of this application.</p>
|
2236
|
+
</div>
|
2237
|
+
|
2238
|
+
</li>
|
2239
|
+
|
2240
|
+
</ul>
|
2241
|
+
|
2242
|
+
<p class="tag_title">Returns:</p>
|
2243
|
+
<ul class="return">
|
2244
|
+
|
2245
|
+
<li>
|
2246
|
+
|
2247
|
+
|
2248
|
+
<span class='type'>(<tt>String|nil</tt>)</span>
|
2249
|
+
|
2250
|
+
|
2251
|
+
|
2252
|
+
—
|
2253
|
+
<div class='inline'><p>The version of this application.</p>
|
2254
|
+
</div>
|
2255
|
+
|
2256
|
+
</li>
|
2257
|
+
|
2258
|
+
</ul>
|
2259
|
+
|
2260
|
+
</div><table class="source_code">
|
2261
|
+
<tr>
|
2262
|
+
<td>
|
2263
|
+
<pre class="lines">
|
2264
|
+
|
2265
|
+
|
2266
|
+
72
|
2267
|
+
73
|
2268
|
+
74
|
2269
|
+
75
|
2270
|
+
76
|
2271
|
+
77
|
2272
|
+
78
|
2273
|
+
79
|
2274
|
+
80
|
2275
|
+
81
|
2276
|
+
82
|
2277
|
+
83
|
2278
|
+
84
|
2279
|
+
85
|
2280
|
+
86
|
2281
|
+
87
|
2282
|
+
88
|
2283
|
+
89
|
2284
|
+
90
|
2285
|
+
91
|
2286
|
+
92
|
2287
|
+
93
|
2288
|
+
94
|
2289
|
+
95
|
2290
|
+
96
|
2291
|
+
97
|
2292
|
+
98
|
2293
|
+
99
|
2294
|
+
100
|
2295
|
+
101
|
2296
|
+
102
|
2297
|
+
103
|
2298
|
+
104
|
2299
|
+
105
|
2300
|
+
106
|
2301
|
+
107
|
2302
|
+
108
|
2303
|
+
109
|
2304
|
+
110
|
2305
|
+
111
|
2306
|
+
112
|
2307
|
+
113
|
2308
|
+
114
|
2309
|
+
115
|
2310
|
+
116
|
2311
|
+
117
|
2312
|
+
118
|
2313
|
+
119
|
2314
|
+
120
|
2315
|
+
121
|
2316
|
+
122
|
2317
|
+
123
|
2318
|
+
124
|
2319
|
+
125
|
2320
|
+
126
|
2321
|
+
127
|
2322
|
+
128
|
2323
|
+
129
|
2324
|
+
130
|
2325
|
+
131
|
2326
|
+
132
|
2327
|
+
133
|
2328
|
+
134
|
2329
|
+
135
|
2330
|
+
136
|
2331
|
+
137
|
2332
|
+
138
|
2333
|
+
139
|
2334
|
+
140
|
2335
|
+
141
|
2336
|
+
142
|
2337
|
+
143
|
2338
|
+
144
|
2339
|
+
145
|
2340
|
+
146
|
2341
|
+
147
|
2342
|
+
148
|
2343
|
+
149
|
2344
|
+
150
|
2345
|
+
151
|
2346
|
+
152
|
2347
|
+
153
|
2348
|
+
154
|
2349
|
+
155
|
2350
|
+
156
|
2351
|
+
157
|
2352
|
+
158
|
2353
|
+
159
|
2354
|
+
160
|
2355
|
+
161
|
2356
|
+
162
|
2357
|
+
163
|
2358
|
+
164
|
2359
|
+
165
|
2360
|
+
166
|
2361
|
+
167
|
2362
|
+
168
|
2363
|
+
169
|
2364
|
+
170
|
2365
|
+
171
|
2366
|
+
172
|
2367
|
+
173
|
2368
|
+
174
|
2369
|
+
175
|
2370
|
+
176
|
2371
|
+
177
|
2372
|
+
178
|
2373
|
+
179
|
2374
|
+
180
|
2375
|
+
181
|
2376
|
+
182
|
2377
|
+
183
|
2378
|
+
184
|
2379
|
+
185
|
2380
|
+
186
|
2381
|
+
187
|
2382
|
+
188
|
2383
|
+
189
|
2384
|
+
190
|
2385
|
+
191
|
2386
|
+
192
|
2387
|
+
193
|
2388
|
+
194
|
2389
|
+
195
|
2390
|
+
196
|
2391
|
+
197
|
2392
|
+
198
|
2393
|
+
199
|
2394
|
+
200
|
2395
|
+
201
|
2396
|
+
202
|
2397
|
+
203
|
2398
|
+
204
|
2399
|
+
205</pre>
|
2400
|
+
</td>
|
2401
|
+
<td>
|
2402
|
+
<pre class="code"><span class="info file"># File 'lib/mamertes/application.rb', line 72</span>
|
2403
|
+
|
2404
|
+
<span class='kw'>class</span> <span class='const'>Application</span> <span class='op'><</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Command</span>
|
2405
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:version</span>
|
2406
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:shell</span>
|
2407
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:console</span>
|
2408
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:skip_commands</span>
|
2409
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:show_commands</span>
|
2410
|
+
<span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:output_commands</span>
|
2411
|
+
|
2412
|
+
<span class='comment'># Initializes a new Mamertes application.
|
2413
|
+
</span> <span class='comment'>#
|
2414
|
+
</span> <span class='comment'># In options, you can override the command line arguments with `:__args__`, and you can skip execution by specifying `run: false`.
|
2415
|
+
</span> <span class='comment'>#
|
2416
|
+
</span> <span class='comment'># @see Command#setup_with
|
2417
|
+
</span> <span class='comment'>#
|
2418
|
+
</span> <span class='comment'># @param options [Hash] The settings to initialize the application with.
|
2419
|
+
</span> <span class='comment'># @return [Application] The created application.
|
2420
|
+
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2421
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Error</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Application</span><span class='comma'>,</span> <span class='symbol'>:missing_block</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_localize_on_locale'>localize_on_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='symbol'>:missing_app_block</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_block_given?'>block_given?</span>
|
2422
|
+
<span class='id identifier rubyid_run'>run</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='id identifier rubyid_setup_application_option'>setup_application_option</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
|
2423
|
+
|
2424
|
+
<span class='kw'>begin</span>
|
2425
|
+
<span class='id identifier rubyid_create_application'>create_application</span><span class='lparen'>(</span><span class='id identifier rubyid_run'>run</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2426
|
+
<span class='kw'>rescue</span> <span class='op'>=></span> <span class='id identifier rubyid_e'>e</span>
|
2427
|
+
<span class='const'>Kernel</span><span class='period'>.</span><span class='id identifier rubyid_puts'>puts</span><span class='lparen'>(</span><span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span>
|
2428
|
+
<span class='const'>Kernel</span><span class='period'>.</span><span class='id identifier rubyid_exit'>exit</span><span class='lparen'>(</span><span class='int'>1</span><span class='rparen'>)</span>
|
2429
|
+
<span class='kw'>end</span>
|
2430
|
+
<span class='kw'>end</span>
|
2431
|
+
|
2432
|
+
<span class='comment'># Creates a new application.
|
2433
|
+
</span> <span class='comment'>#
|
2434
|
+
</span> <span class='comment'># @param options [Hash] The settings to initialize the application with.
|
2435
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2436
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2437
|
+
|
2438
|
+
<span class='ivar'>@shell</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Bovem</span><span class='op'>::</span><span class='const'>Shell</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span>
|
2439
|
+
<span class='ivar'>@console</span> <span class='op'>=</span> <span class='ivar'>@shell</span><span class='period'>.</span><span class='id identifier rubyid_console'>console</span>
|
2440
|
+
<span class='ivar'>@skip_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
2441
|
+
<span class='ivar'>@show_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
2442
|
+
<span class='ivar'>@output_commands</span> <span class='op'>=</span> <span class='kw'>false</span>
|
2443
|
+
|
2444
|
+
<span class='id identifier rubyid_help_option'>help_option</span>
|
2445
|
+
<span class='kw'>end</span>
|
2446
|
+
|
2447
|
+
<span class='comment'># Reads and optionally sets the version of this application.
|
2448
|
+
</span> <span class='comment'>#
|
2449
|
+
</span> <span class='comment'># @param value [String|nil] The new version of this application.
|
2450
|
+
</span> <span class='comment'># @return [String|nil] The version of this application.
|
2451
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_version'>version</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
2452
|
+
<span class='ivar'>@version</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span> <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
2453
|
+
<span class='ivar'>@version</span>
|
2454
|
+
<span class='kw'>end</span>
|
2455
|
+
|
2456
|
+
<span class='comment'># Executes this application.
|
2457
|
+
</span> <span class='comment'>#
|
2458
|
+
</span> <span class='comment'># @param args [Array] The command line to pass to this application. Defaults to `ARGV`.
|
2459
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
2460
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span> <span class='op'>||</span> <span class='const'>ARGV</span><span class='rparen'>)</span>
|
2461
|
+
<span class='kw'>end</span>
|
2462
|
+
|
2463
|
+
<span class='comment'># Adds a help command and a help option to this application.
|
2464
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_help_option'>help_option</span>
|
2465
|
+
<span class='id identifier rubyid_command'>command</span><span class='lparen'>(</span><span class='symbol'>:help</span><span class='comma'>,</span> <span class='label'>description:</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_command_description'>help_command_description</span><span class='rparen'>)</span> <span class='kw'>do</span>
|
2466
|
+
<span class='id identifier rubyid_action'>action</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_command'>command</span><span class='op'>|</span> <span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_command_help'>command_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
2467
|
+
<span class='kw'>end</span>
|
2468
|
+
|
2469
|
+
<span class='id identifier rubyid_option'>option</span><span class='lparen'>(</span><span class='symbol'>:help</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_option_short_form'>help_option_short_form</span><span class='comma'>,</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_option_long_form'>help_option_long_form</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='label'>help:</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_message'>help_message</span><span class='rparen'>)</span><span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_application'>application</span><span class='comma'>,</span> <span class='id identifier rubyid__'>_</span><span class='op'>|</span> <span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_show_help'>show_help</span> <span class='rbrace'>}</span>
|
2470
|
+
<span class='kw'>end</span>
|
2471
|
+
|
2472
|
+
<span class='comment'># The name of the current executable.
|
2473
|
+
</span> <span class='comment'>#
|
2474
|
+
</span> <span class='comment'># @return [String] The name of the current executable.
|
2475
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_executable_name'>executable_name</span>
|
2476
|
+
<span class='gvar'>$0</span>
|
2477
|
+
<span class='kw'>end</span>
|
2478
|
+
|
2479
|
+
<span class='comment'># Shows a help about a command.
|
2480
|
+
</span> <span class='comment'>#
|
2481
|
+
</span> <span class='comment'># @param command [Command] The command to show help for.
|
2482
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_command_help'>command_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span>
|
2483
|
+
<span class='id identifier rubyid_fetch_commands_for_help'>fetch_commands_for_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_arg'>arg</span><span class='op'>|</span>
|
2484
|
+
<span class='comment'># Find the command across
|
2485
|
+
</span> <span class='id identifier rubyid_next_command'>next_command</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Parser</span><span class='period'>.</span><span class='id identifier rubyid_find_command'>find_command</span><span class='lparen'>(</span><span class='id identifier rubyid_arg'>arg</span><span class='comma'>,</span> <span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
2486
|
+
|
2487
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_next_command'>next_command</span> <span class='kw'>then</span>
|
2488
|
+
<span class='id identifier rubyid_command'>command</span> <span class='op'>=</span> <span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_commands'>commands</span><span class='lbracket'>[</span><span class='id identifier rubyid_next_command'>next_command</span><span class='lbracket'>[</span><span class='symbol'>:name</span><span class='rbracket'>]</span><span class='rbracket'>]</span>
|
2489
|
+
<span class='kw'>else</span>
|
2490
|
+
<span class='kw'>break</span>
|
2491
|
+
<span class='kw'>end</span>
|
2492
|
+
<span class='kw'>end</span>
|
2493
|
+
|
2494
|
+
<span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_show_help'>show_help</span>
|
2495
|
+
<span class='kw'>end</span>
|
2496
|
+
|
2497
|
+
<span class='comment'># Runs a command into the shell.
|
2498
|
+
</span> <span class='comment'>#
|
2499
|
+
</span> <span class='comment'># @param command [String] The string to run.
|
2500
|
+
</span> <span class='comment'># @param message [String] A message to show before running.
|
2501
|
+
</span> <span class='comment'># @param show_exit [Boolean] If show the exit status.
|
2502
|
+
</span> <span class='comment'># @param fatal [Boolean] If quit in case of fatal errors.
|
2503
|
+
</span> <span class='comment'># @return [Hash] An hash with `status` and `output` keys.
|
2504
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_run'>run</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_show_exit'>show_exit</span> <span class='op'>=</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='id identifier rubyid_fatal'>fatal</span> <span class='op'>=</span> <span class='kw'>true</span><span class='rparen'>)</span>
|
2505
|
+
<span class='ivar'>@shell</span><span class='period'>.</span><span class='id identifier rubyid_run'>run</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>!</span><span class='ivar'>@skip_commands</span><span class='comma'>,</span> <span class='id identifier rubyid_show_exit'>show_exit</span><span class='comma'>,</span> <span class='ivar'>@output_commands</span><span class='comma'>,</span> <span class='ivar'>@show_commands</span><span class='comma'>,</span> <span class='id identifier rubyid_fatal'>fatal</span><span class='rparen'>)</span>
|
2506
|
+
<span class='kw'>end</span>
|
2507
|
+
|
2508
|
+
<span class='id identifier rubyid_private'>private</span>
|
2509
|
+
<span class='comment'># Setup options for application creation.
|
2510
|
+
</span> <span class='comment'>#
|
2511
|
+
</span> <span class='comment'># @param options [Hash] The options to setups.
|
2512
|
+
</span> <span class='comment'># @return [Array] If to run the application, the arguments and the specified options.
|
2513
|
+
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_setup_application_option'>setup_application_option</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
|
2514
|
+
<span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='label'>name:</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_localize_on_locale'>localize_on_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='symbol'>:default_application_name</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='label'>parent:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>application:</span> <span class='kw'>nil</span><span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_ensure_hash'>ensure_hash</span><span class='rparen'>)</span>
|
2515
|
+
<span class='id identifier rubyid_run'>run</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:run</span><span class='rparen'>)</span>
|
2516
|
+
<span class='lbracket'>[</span><span class='lparen'>(</span><span class='op'>!</span><span class='id identifier rubyid_run'>run</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> <span class='op'>?</span> <span class='id identifier rubyid_run'>run</span> <span class='op'>:</span> <span class='kw'>true</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_boolean'>to_boolean</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='symbol'>:__args__</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='rbracket'>]</span>
|
2517
|
+
<span class='kw'>end</span>
|
2518
|
+
|
2519
|
+
<span class='comment'># Create the application.
|
2520
|
+
</span> <span class='comment'>#
|
2521
|
+
</span> <span class='comment'># @param run [Boolean ]If to run the application.
|
2522
|
+
</span> <span class='comment'># @param args [Hash] The arguments to use for running.
|
2523
|
+
</span> <span class='comment'># @param options [Hash] The options of the application.
|
2524
|
+
</span> <span class='comment'># @return [Application] The new application.
|
2525
|
+
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create_application'>create_application</span><span class='lparen'>(</span><span class='id identifier rubyid_run'>run</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2526
|
+
<span class='id identifier rubyid_application'>application</span> <span class='op'>=</span> <span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2527
|
+
<span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_application'>application</span> <span class='op'>&&</span> <span class='id identifier rubyid_run'>run</span>
|
2528
|
+
<span class='id identifier rubyid_application'>application</span>
|
2529
|
+
<span class='kw'>end</span>
|
2530
|
+
|
2531
|
+
<span class='comment'># Fetch a command list for showing help.
|
2532
|
+
</span> <span class='comment'>#
|
2533
|
+
</span> <span class='comment'># @param command [Command] The command to show help for.
|
2534
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_fetch_commands_for_help'>fetch_commands_for_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span>
|
2535
|
+
<span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_c'>c</span><span class='op'>|</span> <span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_split'>split</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>:</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:strip</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_select'>select</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:present?</span><span class='rparen'>)</span>
|
2536
|
+
<span class='kw'>end</span>
|
2537
|
+
<span class='kw'>end</span></pre>
|
2538
|
+
</td>
|
2539
|
+
</tr>
|
2540
|
+
</table>
|
2541
|
+
</div>
|
2542
|
+
|
2543
|
+
</div>
|
2544
|
+
|
2545
|
+
|
2546
|
+
<div id="class_method_details" class="method_details_list">
|
2547
|
+
<h2>Class Method Details</h2>
|
2548
|
+
|
2549
|
+
|
2550
|
+
<div class="method_details first">
|
2551
|
+
<h3 class="signature first" id="create-class_method">
|
2552
|
+
|
2553
|
+
+ (<tt><span class='object_link'><a href="" title="Mamertes::Application (class)">Application</a></span></tt>) <strong>create</strong>(options = {}, &block)
|
2554
|
+
|
2555
|
+
|
2556
|
+
|
2557
|
+
|
2558
|
+
|
2559
|
+
</h3><div class="docstring">
|
2560
|
+
<div class="discussion">
|
2561
|
+
<p>Initializes a new Mamertes application.</p>
|
2562
|
+
|
2563
|
+
<p>In options, you can override the command line arguments with <code>:__args__</code>, and you can skip execution by specifying <code>run: false</code>.</p>
|
2564
|
+
|
2565
|
+
|
2566
|
+
</div>
|
2567
|
+
</div>
|
2568
|
+
<div class="tags">
|
2569
|
+
<p class="tag_title">Parameters:</p>
|
2570
|
+
<ul class="param">
|
2571
|
+
|
2572
|
+
<li>
|
2573
|
+
|
2574
|
+
<span class='name'>options</span>
|
2575
|
+
|
2576
|
+
|
2577
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
2578
|
+
|
2579
|
+
|
2580
|
+
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
2581
|
+
|
2582
|
+
|
2583
|
+
—
|
2584
|
+
<div class='inline'><p>The settings to initialize the application with.</p>
|
2585
|
+
</div>
|
2586
|
+
|
2587
|
+
</li>
|
2588
|
+
|
2589
|
+
</ul>
|
2590
|
+
|
2591
|
+
<p class="tag_title">Returns:</p>
|
2592
|
+
<ul class="return">
|
2593
|
+
|
2594
|
+
<li>
|
2595
|
+
|
2596
|
+
|
2597
|
+
<span class='type'>(<tt><span class='object_link'><a href="" title="Mamertes::Application (class)">Application</a></span></tt>)</span>
|
2598
|
+
|
2599
|
+
|
2600
|
+
|
2601
|
+
—
|
2602
|
+
<div class='inline'><p>The created application.</p>
|
2603
|
+
</div>
|
2604
|
+
|
2605
|
+
</li>
|
2606
|
+
|
2607
|
+
</ul>
|
2608
|
+
<p class="tag_title">Raises:</p>
|
2609
|
+
<ul class="raise">
|
2610
|
+
|
2611
|
+
<li>
|
2612
|
+
|
2613
|
+
|
2614
|
+
<span class='type'>(<tt><span class='object_link'><a href="Error.html" title="Mamertes::Error (class)">Mamertes::Error</a></span></tt>)</span>
|
2615
|
+
|
2616
|
+
|
2617
|
+
|
2618
|
+
</li>
|
2619
|
+
|
2620
|
+
</ul>
|
2621
|
+
|
2622
|
+
<p class="tag_title">See Also:</p>
|
2623
|
+
<ul class="see">
|
2624
|
+
|
2625
|
+
<li><span class='object_link'><a href="Command.html#setup_with-instance_method" title="Mamertes::Command#setup_with (method)">Command#setup_with</a></span></li>
|
2626
|
+
|
2627
|
+
</ul>
|
2628
|
+
|
2629
|
+
</div><table class="source_code">
|
2630
|
+
<tr>
|
2631
|
+
<td>
|
2632
|
+
<pre class="lines">
|
2633
|
+
|
2634
|
+
|
2635
|
+
88
|
2636
|
+
89
|
2637
|
+
90
|
2638
|
+
91
|
2639
|
+
92
|
2640
|
+
93
|
2641
|
+
94
|
2642
|
+
95
|
2643
|
+
96
|
2644
|
+
97
|
2645
|
+
98</pre>
|
2646
|
+
</td>
|
2647
|
+
<td>
|
2648
|
+
<pre class="code"><span class="info file"># File 'lib/mamertes/application.rb', line 88</span>
|
2649
|
+
|
2650
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2651
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Error</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Application</span><span class='comma'>,</span> <span class='symbol'>:missing_block</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Localizer</span><span class='period'>.</span><span class='id identifier rubyid_localize_on_locale'>localize_on_locale</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:locale</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='symbol'>:missing_app_block</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_block_given?'>block_given?</span>
|
2652
|
+
<span class='id identifier rubyid_run'>run</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='id identifier rubyid_setup_application_option'>setup_application_option</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
|
2653
|
+
|
2654
|
+
<span class='kw'>begin</span>
|
2655
|
+
<span class='id identifier rubyid_create_application'>create_application</span><span class='lparen'>(</span><span class='id identifier rubyid_run'>run</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2656
|
+
<span class='kw'>rescue</span> <span class='op'>=></span> <span class='id identifier rubyid_e'>e</span>
|
2657
|
+
<span class='const'>Kernel</span><span class='period'>.</span><span class='id identifier rubyid_puts'>puts</span><span class='lparen'>(</span><span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span>
|
2658
|
+
<span class='const'>Kernel</span><span class='period'>.</span><span class='id identifier rubyid_exit'>exit</span><span class='lparen'>(</span><span class='int'>1</span><span class='rparen'>)</span>
|
2659
|
+
<span class='kw'>end</span>
|
2660
|
+
<span class='kw'>end</span></pre>
|
2661
|
+
</td>
|
2662
|
+
</tr>
|
2663
|
+
</table>
|
2664
|
+
</div>
|
2665
|
+
|
2666
|
+
</div>
|
2667
|
+
|
2668
|
+
<div id="instance_method_details" class="method_details_list">
|
2669
|
+
<h2>Instance Method Details</h2>
|
2670
|
+
|
2671
|
+
|
2672
|
+
<div class="method_details first">
|
2673
|
+
<h3 class="signature first" id="command_help-instance_method">
|
2674
|
+
|
2675
|
+
- (<tt>Object</tt>) <strong>command_help</strong>(command)
|
2676
|
+
|
2677
|
+
|
2678
|
+
|
2679
|
+
|
2680
|
+
|
2681
|
+
</h3><div class="docstring">
|
2682
|
+
<div class="discussion">
|
2683
|
+
<p>Shows a help about a command.</p>
|
2684
|
+
|
2685
|
+
|
2686
|
+
</div>
|
2687
|
+
</div>
|
2688
|
+
<div class="tags">
|
2689
|
+
<p class="tag_title">Parameters:</p>
|
2690
|
+
<ul class="param">
|
2691
|
+
|
2692
|
+
<li>
|
2693
|
+
|
2694
|
+
<span class='name'>command</span>
|
2695
|
+
|
2696
|
+
|
2697
|
+
<span class='type'>(<tt><span class='object_link'><a href="Command.html" title="Mamertes::Command (class)">Command</a></span></tt>)</span>
|
2698
|
+
|
2699
|
+
|
2700
|
+
|
2701
|
+
—
|
2702
|
+
<div class='inline'><p>The command to show help for.</p>
|
2703
|
+
</div>
|
2704
|
+
|
2705
|
+
</li>
|
2706
|
+
|
2707
|
+
</ul>
|
2708
|
+
|
2709
|
+
|
2710
|
+
</div><table class="source_code">
|
2711
|
+
<tr>
|
2712
|
+
<td>
|
2713
|
+
<pre class="lines">
|
2714
|
+
|
2715
|
+
|
2716
|
+
150
|
2717
|
+
151
|
2718
|
+
152
|
2719
|
+
153
|
2720
|
+
154
|
2721
|
+
155
|
2722
|
+
156
|
2723
|
+
157
|
2724
|
+
158
|
2725
|
+
159
|
2726
|
+
160
|
2727
|
+
161
|
2728
|
+
162
|
2729
|
+
163</pre>
|
2730
|
+
</td>
|
2731
|
+
<td>
|
2732
|
+
<pre class="code"><span class="info file"># File 'lib/mamertes/application.rb', line 150</span>
|
2733
|
+
|
2734
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_command_help'>command_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span>
|
2735
|
+
<span class='id identifier rubyid_fetch_commands_for_help'>fetch_commands_for_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_arg'>arg</span><span class='op'>|</span>
|
2736
|
+
<span class='comment'># Find the command across
|
2737
|
+
</span> <span class='id identifier rubyid_next_command'>next_command</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Mamertes</span><span class='op'>::</span><span class='const'>Parser</span><span class='period'>.</span><span class='id identifier rubyid_find_command'>find_command</span><span class='lparen'>(</span><span class='id identifier rubyid_arg'>arg</span><span class='comma'>,</span> <span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
2738
|
+
|
2739
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_next_command'>next_command</span> <span class='kw'>then</span>
|
2740
|
+
<span class='id identifier rubyid_command'>command</span> <span class='op'>=</span> <span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_commands'>commands</span><span class='lbracket'>[</span><span class='id identifier rubyid_next_command'>next_command</span><span class='lbracket'>[</span><span class='symbol'>:name</span><span class='rbracket'>]</span><span class='rbracket'>]</span>
|
2741
|
+
<span class='kw'>else</span>
|
2742
|
+
<span class='kw'>break</span>
|
2743
|
+
<span class='kw'>end</span>
|
2744
|
+
<span class='kw'>end</span>
|
2745
|
+
|
2746
|
+
<span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_show_help'>show_help</span>
|
2747
|
+
<span class='kw'>end</span></pre>
|
2748
|
+
</td>
|
2749
|
+
</tr>
|
2750
|
+
</table>
|
2751
|
+
</div>
|
2752
|
+
|
2753
|
+
<div class="method_details ">
|
2754
|
+
<h3 class="signature " id="executable_name-instance_method">
|
2755
|
+
|
2756
|
+
- (<tt>String</tt>) <strong>executable_name</strong>
|
2757
|
+
|
2758
|
+
|
2759
|
+
|
2760
|
+
|
2761
|
+
|
2762
|
+
</h3><div class="docstring">
|
2763
|
+
<div class="discussion">
|
2764
|
+
<p>The name of the current executable.</p>
|
2765
|
+
|
2766
|
+
|
2767
|
+
</div>
|
2768
|
+
</div>
|
2769
|
+
<div class="tags">
|
2770
|
+
|
2771
|
+
<p class="tag_title">Returns:</p>
|
2772
|
+
<ul class="return">
|
2773
|
+
|
2774
|
+
<li>
|
2775
|
+
|
2776
|
+
|
2777
|
+
<span class='type'>(<tt>String</tt>)</span>
|
2778
|
+
|
2779
|
+
|
2780
|
+
|
2781
|
+
—
|
2782
|
+
<div class='inline'><p>The name of the current executable.</p>
|
2783
|
+
</div>
|
2784
|
+
|
2785
|
+
</li>
|
2786
|
+
|
2787
|
+
</ul>
|
2788
|
+
|
2789
|
+
</div><table class="source_code">
|
2790
|
+
<tr>
|
2791
|
+
<td>
|
2792
|
+
<pre class="lines">
|
2793
|
+
|
2794
|
+
|
2795
|
+
143
|
2796
|
+
144
|
2797
|
+
145</pre>
|
2798
|
+
</td>
|
2799
|
+
<td>
|
2800
|
+
<pre class="code"><span class="info file"># File 'lib/mamertes/application.rb', line 143</span>
|
2801
|
+
|
2802
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_executable_name'>executable_name</span>
|
2803
|
+
<span class='gvar'>$0</span>
|
2804
|
+
<span class='kw'>end</span></pre>
|
2805
|
+
</td>
|
2806
|
+
</tr>
|
2807
|
+
</table>
|
2808
|
+
</div>
|
2809
|
+
|
2810
|
+
<div class="method_details ">
|
2811
|
+
<h3 class="signature " id="execute-instance_method">
|
2812
|
+
|
2813
|
+
- (<tt>Object</tt>) <strong>execute</strong>(args = nil)
|
2814
|
+
|
2815
|
+
|
2816
|
+
|
2817
|
+
|
2818
|
+
|
2819
|
+
</h3><div class="docstring">
|
2820
|
+
<div class="discussion">
|
2821
|
+
<p>Executes this application.</p>
|
2822
|
+
|
2823
|
+
|
2824
|
+
</div>
|
2825
|
+
</div>
|
2826
|
+
<div class="tags">
|
2827
|
+
<p class="tag_title">Parameters:</p>
|
2828
|
+
<ul class="param">
|
2829
|
+
|
2830
|
+
<li>
|
2831
|
+
|
2832
|
+
<span class='name'>args</span>
|
2833
|
+
|
2834
|
+
|
2835
|
+
<span class='type'>(<tt>Array</tt>)</span>
|
2836
|
+
|
2837
|
+
|
2838
|
+
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
2839
|
+
|
2840
|
+
|
2841
|
+
—
|
2842
|
+
<div class='inline'><p>The command line to pass to this application. Defaults to <code>ARGV</code>.</p>
|
2843
|
+
</div>
|
2844
|
+
|
2845
|
+
</li>
|
2846
|
+
|
2847
|
+
</ul>
|
2848
|
+
|
2849
|
+
|
2850
|
+
</div><table class="source_code">
|
2851
|
+
<tr>
|
2852
|
+
<td>
|
2853
|
+
<pre class="lines">
|
2854
|
+
|
2855
|
+
|
2856
|
+
127
|
2857
|
+
128
|
2858
|
+
129</pre>
|
2859
|
+
</td>
|
2860
|
+
<td>
|
2861
|
+
<pre class="code"><span class="info file"># File 'lib/mamertes/application.rb', line 127</span>
|
2862
|
+
|
2863
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
2864
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span> <span class='op'>||</span> <span class='const'>ARGV</span><span class='rparen'>)</span>
|
2865
|
+
<span class='kw'>end</span></pre>
|
2866
|
+
</td>
|
2867
|
+
</tr>
|
2868
|
+
</table>
|
2869
|
+
</div>
|
2870
|
+
|
2871
|
+
<div class="method_details ">
|
2872
|
+
<h3 class="signature " id="help_option-instance_method">
|
2873
|
+
|
2874
|
+
- (<tt>Object</tt>) <strong>help_option</strong>
|
2875
|
+
|
2876
|
+
|
2877
|
+
|
2878
|
+
|
2879
|
+
|
2880
|
+
</h3><div class="docstring">
|
2881
|
+
<div class="discussion">
|
2882
|
+
<p>Adds a help command and a help option to this application.</p>
|
2883
|
+
|
2884
|
+
|
2885
|
+
</div>
|
2886
|
+
</div>
|
2887
|
+
<div class="tags">
|
2888
|
+
|
2889
|
+
|
2890
|
+
</div><table class="source_code">
|
2891
|
+
<tr>
|
2892
|
+
<td>
|
2893
|
+
<pre class="lines">
|
2894
|
+
|
2895
|
+
|
2896
|
+
132
|
2897
|
+
133
|
2898
|
+
134
|
2899
|
+
135
|
2900
|
+
136
|
2901
|
+
137
|
2902
|
+
138</pre>
|
2903
|
+
</td>
|
2904
|
+
<td>
|
2905
|
+
<pre class="code"><span class="info file"># File 'lib/mamertes/application.rb', line 132</span>
|
2906
|
+
|
2907
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_help_option'>help_option</span>
|
2908
|
+
<span class='id identifier rubyid_command'>command</span><span class='lparen'>(</span><span class='symbol'>:help</span><span class='comma'>,</span> <span class='label'>description:</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_command_description'>help_command_description</span><span class='rparen'>)</span> <span class='kw'>do</span>
|
2909
|
+
<span class='id identifier rubyid_action'>action</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_command'>command</span><span class='op'>|</span> <span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_command_help'>command_help</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
2910
|
+
<span class='kw'>end</span>
|
2911
|
+
|
2912
|
+
<span class='id identifier rubyid_option'>option</span><span class='lparen'>(</span><span class='symbol'>:help</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_option_short_form'>help_option_short_form</span><span class='comma'>,</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_option_long_form'>help_option_long_form</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='label'>help:</span> <span class='id identifier rubyid_i18n'>i18n</span><span class='period'>.</span><span class='id identifier rubyid_help_message'>help_message</span><span class='rparen'>)</span><span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_application'>application</span><span class='comma'>,</span> <span class='id identifier rubyid__'>_</span><span class='op'>|</span> <span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_show_help'>show_help</span> <span class='rbrace'>}</span>
|
2913
|
+
<span class='kw'>end</span></pre>
|
2914
|
+
</td>
|
2915
|
+
</tr>
|
2916
|
+
</table>
|
2917
|
+
</div>
|
2918
|
+
|
2919
|
+
<div class="method_details ">
|
2920
|
+
<h3 class="signature " id="run-instance_method">
|
2921
|
+
|
2922
|
+
- (<tt>Hash</tt>) <strong>run</strong>(command, message = nil, show_exit = true, fatal = true)
|
2923
|
+
|
2924
|
+
|
2925
|
+
|
2926
|
+
|
2927
|
+
|
2928
|
+
</h3><div class="docstring">
|
2929
|
+
<div class="discussion">
|
2930
|
+
<p>Runs a command into the shell.</p>
|
2931
|
+
|
2932
|
+
|
2933
|
+
</div>
|
2934
|
+
</div>
|
2935
|
+
<div class="tags">
|
2936
|
+
<p class="tag_title">Parameters:</p>
|
2937
|
+
<ul class="param">
|
2938
|
+
|
2939
|
+
<li>
|
2940
|
+
|
2941
|
+
<span class='name'>command</span>
|
2942
|
+
|
2943
|
+
|
2944
|
+
<span class='type'>(<tt>String</tt>)</span>
|
2945
|
+
|
2946
|
+
|
2947
|
+
|
2948
|
+
—
|
2949
|
+
<div class='inline'><p>The string to run.</p>
|
2950
|
+
</div>
|
2951
|
+
|
2952
|
+
</li>
|
2953
|
+
|
2954
|
+
<li>
|
2955
|
+
|
2956
|
+
<span class='name'>message</span>
|
2957
|
+
|
2958
|
+
|
2959
|
+
<span class='type'>(<tt>String</tt>)</span>
|
2960
|
+
|
2961
|
+
|
2962
|
+
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
2963
|
+
|
2964
|
+
|
2965
|
+
—
|
2966
|
+
<div class='inline'><p>A message to show before running.</p>
|
2967
|
+
</div>
|
2968
|
+
|
2969
|
+
</li>
|
2970
|
+
|
2971
|
+
<li>
|
2972
|
+
|
2973
|
+
<span class='name'>show_exit</span>
|
2974
|
+
|
2975
|
+
|
2976
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
2977
|
+
|
2978
|
+
|
2979
|
+
<em class="default">(defaults to: <tt>true</tt>)</em>
|
2980
|
+
|
2981
|
+
|
2982
|
+
—
|
2983
|
+
<div class='inline'><p>If show the exit status.</p>
|
2984
|
+
</div>
|
2985
|
+
|
2986
|
+
</li>
|
2987
|
+
|
2988
|
+
<li>
|
2989
|
+
|
2990
|
+
<span class='name'>fatal</span>
|
2991
|
+
|
2992
|
+
|
2993
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
2994
|
+
|
2995
|
+
|
2996
|
+
<em class="default">(defaults to: <tt>true</tt>)</em>
|
2997
|
+
|
2998
|
+
|
2999
|
+
—
|
3000
|
+
<div class='inline'><p>If quit in case of fatal errors.</p>
|
3001
|
+
</div>
|
3002
|
+
|
3003
|
+
</li>
|
3004
|
+
|
3005
|
+
</ul>
|
3006
|
+
|
3007
|
+
<p class="tag_title">Returns:</p>
|
3008
|
+
<ul class="return">
|
3009
|
+
|
3010
|
+
<li>
|
3011
|
+
|
3012
|
+
|
3013
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
3014
|
+
|
3015
|
+
|
3016
|
+
|
3017
|
+
—
|
3018
|
+
<div class='inline'><p>An hash with <code>status</code> and <code>output</code> keys.</p>
|
3019
|
+
</div>
|
3020
|
+
|
3021
|
+
</li>
|
3022
|
+
|
3023
|
+
</ul>
|
3024
|
+
|
3025
|
+
</div><table class="source_code">
|
3026
|
+
<tr>
|
3027
|
+
<td>
|
3028
|
+
<pre class="lines">
|
3029
|
+
|
3030
|
+
|
3031
|
+
172
|
3032
|
+
173
|
3033
|
+
174</pre>
|
3034
|
+
</td>
|
3035
|
+
<td>
|
3036
|
+
<pre class="code"><span class="info file"># File 'lib/mamertes/application.rb', line 172</span>
|
3037
|
+
|
3038
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_run'>run</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_show_exit'>show_exit</span> <span class='op'>=</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='id identifier rubyid_fatal'>fatal</span> <span class='op'>=</span> <span class='kw'>true</span><span class='rparen'>)</span>
|
3039
|
+
<span class='ivar'>@shell</span><span class='period'>.</span><span class='id identifier rubyid_run'>run</span><span class='lparen'>(</span><span class='id identifier rubyid_command'>command</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='op'>!</span><span class='ivar'>@skip_commands</span><span class='comma'>,</span> <span class='id identifier rubyid_show_exit'>show_exit</span><span class='comma'>,</span> <span class='ivar'>@output_commands</span><span class='comma'>,</span> <span class='ivar'>@show_commands</span><span class='comma'>,</span> <span class='id identifier rubyid_fatal'>fatal</span><span class='rparen'>)</span>
|
3040
|
+
<span class='kw'>end</span></pre>
|
3041
|
+
</td>
|
3042
|
+
</tr>
|
3043
|
+
</table>
|
3044
|
+
</div>
|
3045
|
+
|
3046
|
+
</div>
|
3047
|
+
|
3048
|
+
</div>
|
3049
|
+
|
3050
|
+
<div id="footer">
|
3051
|
+
Generated on Sat Aug 10 16:23:11 2013 by
|
3052
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
3053
|
+
0.8.6.2 (ruby-1.9.3).
|
3054
|
+
</div>
|
3055
|
+
|
3056
|
+
</body>
|
3057
|
+
</html>
|