cmdparse 2.0.6 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,40 +1,61 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{lang:}">
1
+ <!DOCTYPE HTML>
2
+ <html>
4
3
  <head>
5
4
  <title>cmdparse: {title:}</title>
6
- <link href="{relocatable: default.css}" rel="stylesheet" />
7
5
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <meta name="description" content="Advanced Ruby command line parser supporting nested commands" />
7
+ <meta name="keywords" content="ruby, CLI, command parser, command suite, option parser" />
8
+ <link href="{relocatable: default.css}" rel="stylesheet" />
8
9
  </head>
9
- <body>
10
- <div id="all">
11
-
12
- <div id="header">
13
- <table>
14
- <tr>
15
- <td><img src="{relocatable: logo.png}" alt="Logo" title="Logo" /></td>
16
- <td><h1>cmdparse<span style="font-size: 60%"> - advanced command line parser supporting commands</span></h1>
17
- </td>
18
- </tr>
19
- </table>
10
+ <body class="left-sidebar">
11
+ <div id="wrapper">
12
+ <div id="titleBar">
13
+ <a id="sidebar-show" href="#titleBar" class="toggle"></a>
14
+ <a id="sidebar-hide" href="#" class="toggle"></a><span class="title">cmdparse</span>
20
15
  </div>
21
16
 
22
- <div id="headerbar" class="bar">
23
- <span class="left">Navbar: {breadcrumb_trail: }</span>
24
- <div style="clear:both"></div>
17
+ <div id="content">
18
+ <div class="inner">
19
+ <article class="box post">
20
+ <webgen:block name="content" />
21
+ </article>
22
+ </div>
25
23
  </div>
26
24
 
27
- <div id="menu">
28
- {menu: {options: {mi: {in_menu: true}, sort: true}}}
29
- </div>
25
+ <!-- Sidebar -->
26
+ <div id="sidebar">
27
+ <h1 id="logo"><a href="{relocatable: /}">cmdparse</a><br /><span>v 3.0.0</span></h1>
30
28
 
31
- <div id="body">
32
- <webgen:block name="content" />
33
- </div>
29
+ <!-- Nav -->
30
+ <nav id="nav">
31
+ {menu: {options: {mi: {in_menu: true}, sort: true, absolute_levels: [0, 1]},
32
+ item_submenu_inhierarchy_class: current, item_selected_class: current}}
33
+ </nav>
34
+
35
+ <!-- Text -->
36
+ <section class="box text-style1">
37
+ <div class="inner">
38
+ <p>
39
+ <strong>cmdparse:</strong> An advanced Ruby command line parser supporting nested
40
+ commands
41
+ </p>
42
+ </div>
43
+ </section>
44
+
45
+ <!-- Copyright -->
46
+ <ul id="copyright">
47
+ <li itemscope="" itemtype="http://schema.org/Person">&copy; 2004-2015
48
+ <span itemprop="name">Thomas Leitner</span>
49
+ <meta itemprop="email" content="t_leitner@gmx.at" />
50
+ <meta itemprop="url" content="http://gettalong.org" />
51
+ </li>
52
+ <li>Generated by <a href="http://webgen.gettalong.org">webgen</a><br /> on <b>{date: }</b></li>
53
+ <li>Design based on<br />Striped by <a href="http://html5up.net">HTML5 UP</a></li>
54
+ </ul>
34
55
 
35
- <div id="footer" class="bar">
36
- Generated by <a href="http://webgen.gettalong.org">webgen</a> on <b>{date: }</b>
37
56
  </div>
57
+
38
58
  </div>
59
+
39
60
  </body>
40
61
  </html>
Binary file
Binary file
@@ -1,107 +1,114 @@
1
1
  ---
2
- title: Homepage
2
+ title: Home
3
3
  in_menu: true
4
4
  routed_title: cmdparse
5
5
  sort_info: 1
6
6
  ---
7
- ## Welcome
7
+ ## cmdparse
8
8
 
9
- ... to the homepage of ***cmdparse***, an advanced command line parser supporting commands.
9
+ ... is an advanced Ruby command line parser supporting nested commands.
10
10
 
11
- ## Feature List
11
+ It allows the creation of "command style" programs, like `git` or `svn`, that perform different
12
+ functions depending on which command is invoked. Additionally, nesting of commands, i.e. commands
13
+ that take commands themselves, is also possible. For option parsing, the battle-tested Ruby standard
14
+ library `optparse` is used.
12
15
 
13
- * Commands can have subcommands
14
- * Default commands for showing help and the version of the program
15
- * Option parsing library of choice can be used (after writing wrapper), default is `optparse`
16
- * Easy to use
17
-
18
-
19
- ## News
20
-
21
- **2014-04-05 cmdparse 2.0.6 released!!!**
22
-
23
- There were no codewise changes but the used infrastructure and tools have been updated to newer
24
- versions. Also the license information has been added to the gem specification and the tests are now
25
- included in the distribution.
26
-
27
-
28
- **2012-06-09 cmdparse 2.0.5 released!!!**
29
-
30
- Changes:
31
-
32
- * Fixed backwards incompatible change
33
-
34
-
35
- **2012-06-07 cmdparse 2.0.4 released!!!**
16
+ A typical command line for a program which uses commands looks like this:
36
17
 
37
- Changes:
18
+ $ net --verbose ipaddr add 192.168.0.1 193.150.0.1
38
19
 
39
- * Only some minor changes regarding the help output for commands which is nicer now.
40
20
 
21
+ ## Features
41
22
 
42
- **2006-06-17 cmdparse 2.0.2 released!!!**
43
-
44
- Changes:
45
-
46
- * Included two patches from Assaph Mehr:
47
- * partial command matching can now be used (see the [tutorial page](tutorial.html))
48
- * now a banner for the help and version commands can be specified
49
-
50
-
51
- **2006-04-05 cmdparse 2.0.1 released!!!**
52
-
53
- Changes:
54
-
55
- * Just a bug fix release for those using cmdparse with Rubygems. By issuing the command
56
- `require_gem 'cmdparse'` the cmdparse library gets automagically loaded.
57
- * Minor documentation updates
58
-
59
-
60
- **2005-08-16 cmdparse 2.0.0 released!!!**
61
-
62
- This version is not compatible to previous versions of cmdparse as there have been major changes in
63
- the API. However, updating your code to use the new API is very easy!
64
-
65
- Changes:
23
+ * Commands can have sub-commands
24
+ * Built-in commands for showing help and the version of the program
25
+ * Automatic discovery of names and number of required/optional command arguments
26
+ * Truly global options that can be used on any command
27
+ * No need to learn a special DSL
28
+ * Use POROs (plain old Ruby objects) for creating commands or create them on the fly
29
+ * All `OptionParser` goodies available for option parsing
30
+ * Easy to use
66
31
 
67
- * Commands can now have subcommands which can have subcommands which can have subcommands...
68
- * No need to implement a whole new class for simple commands anymore
69
- * Default option parser library is `optparse`, however, any option parser library can be used after writing a small wrapper
70
32
 
33
+ ## Quickstart
71
34
 
72
- **2005-07-05 cmdparse 1.0.5 released!!!**
35
+ Here are two short code samples which show how to use cmdparse. A complete example application can
36
+ be found in the [tutorial](tutorial.html), also see the API documentation of
37
+ [CmdParse::CommandParser] and [CmdParse::Command].
73
38
 
74
- Changes:
39
+ A sample CLI program where commands are defined using classes:
75
40
 
76
- * added possibility to parse global options, command and local options separately
41
+ ~~~ ruby
42
+ require 'cmdparse'
77
43
 
44
+ class TestCmd < CmdParse::Command
45
+ def initialize
46
+ super('test')
47
+ short_desc('Short description of command')
48
+ add_command(TestSubCmd.new)
49
+ end
50
+ end
78
51
 
79
- **2005-06-16 cmdparse 1.0.4 released!!!**
52
+ class TestSubCmd < CmdParse::Command
53
+ def initialize
54
+ super('sub', takes_commands: false)
55
+ options.on('-x', '--example', 'Example option') { puts 'example' }
56
+ end
80
57
 
81
- Changes:
58
+ def execute(name, *opt)
59
+ puts "Hello #{name}, options: #{opt.join(', ')}"
60
+ end
61
+ end
82
62
 
83
- * fix for older ruby versions
84
- * fixed bug where exception was not caught
63
+ parser = CmdParse::CommandParser.new(handle_exceptions: :no_help)
64
+ parser.add_command(CmdParse::HelpCommand.new)
65
+ parser.add_command(TestCmd.new)
66
+ parser.parse
67
+ ~~~
85
68
 
69
+ The same program but with the commands defined on the fly:
86
70
 
87
- **2005-06-09 cmdparse 1.0.3 released!!!**
71
+ ~~~ ruby
72
+ <%= context.render_block('sample') %>
73
+ ~~~
88
74
 
89
- Changes:
75
+ Sample output for different invocations:
90
76
 
91
- * added optional graceful exception handling
77
+ <%
78
+ invocations = ['', 'help', 'test sub', 'test sub -h', 'test sub Thomas', 'test sub -x Thomas opt1 opt2']
79
+ tmpfile = context.website.tmpdir('sample.rb', true)
80
+ File.write(tmpfile, context.render_block('sample'))
81
+ result = invocations.map do |args|
82
+ ["$ <strong>sample.rb #{args}</strong>", h(`ruby -I#{context.website.directory}/lib #{tmpfile} #{args}`)]
83
+ end.flatten.join("\n")
84
+ %>
85
+ <pre>
86
+ <%= result %>
87
+ </pre>
92
88
 
93
89
 
94
- **2005-04-21 cmdparse 1.0.2 released!!!**
95
90
 
96
- Changes:
91
+ ## Author
97
92
 
98
- * splitted parsing of the arguments and executing the command into two methods
93
+ * **Thomas Leitner**
94
+ * Web: <http://cmdparse.gettalong.org>
95
+ * e-Mail: <mailto:t_leitner@gmx.at>
99
96
 
100
97
 
101
- **2005-04-13 cmdparse 1.0.1 released!!!**
98
+ --- name:sample pipeline:
99
+ require 'cmdparse'
102
100
 
103
- Changes:
101
+ parser = CmdParse::CommandParser.new(handle_exceptions: :no_help)
102
+ parser.add_command(CmdParse::HelpCommand.new)
103
+ parser.add_command('test') do |test_cmd|
104
+ test_cmd.short_desc('Short description of command')
104
105
 
105
- * Improved HelpCommand: the global options -h and --help take an optional command name now
106
- * Possibility to define a default command which is used when no command was specified
107
- * A `NoCommandGivenError` is thrown when no command on the CLI and no default command was specified
106
+ test_cmd.add_command('sub') do |sub_cmd|
107
+ sub_cmd.takes_commands(false)
108
+ sub_cmd.options.on('-x', '--example', 'Example option') { puts 'example' }
109
+ sub_cmd.action do |name, *opt|
110
+ puts "Hello #{name}, options: #{opt.join(', ')}"
111
+ end
112
+ end
113
+ end
114
+ parser.parse
@@ -1,29 +1,19 @@
1
1
  ---
2
- title: Download & Installation
2
+ title: Installation
3
3
  in_menu: true
4
4
  sort_info: 4
5
5
  ---
6
- ## Download
6
+ ## Download & Installation
7
7
 
8
8
  The newest version of cmdparse can be downloaded from [Rubygems] or the [cmdparse Github
9
9
  page][github]!
10
10
 
11
- [Rubygems]: http://rubygems.org/gems/cmdparse
12
- [github]: http://github.com/gettalong/cmdparse
13
-
14
-
15
- ## Dependencies
16
-
17
- This library has *no* dependencies.
18
-
19
-
20
- ## Installation
21
-
22
11
  The preferred way of installing cmdparse is via RubyGems:
23
12
 
24
13
  $ gem install cmdparse
25
14
 
26
- If you do not have RubyGems installed, but Rake, you can use the following command:
15
+ If you do not have RubyGems installed, but Rake, you can use the following command inside the
16
+ cmdparse directory:
27
17
 
28
18
  $ rake install
29
19
 
@@ -32,3 +22,12 @@ If you have neither RubyGems nor Rake, use these commands:
32
22
  $ ruby setup.rb config
33
23
  $ ruby setup.rb setup
34
24
  $ ruby setup.rb install
25
+
26
+
27
+ [Rubygems]: http://rubygems.org/gems/cmdparse
28
+ [github]: http://github.com/gettalong/cmdparse
29
+
30
+
31
+ ### Dependencies
32
+
33
+ This library has *no* dependencies.
@@ -0,0 +1,14 @@
1
+ --- alcn
2
+ /api/:
3
+ title: API
4
+ in_menu: true
5
+ sort_info: 10
6
+
7
+ /api/**/*.html:
8
+ link:
9
+ css: /stylesheets/api.css
10
+ in_menu: true
11
+
12
+ /api/**/index*.html:
13
+ in_menu: false
14
+
@@ -0,0 +1,113 @@
1
+ ---
2
+ title: News
3
+ in_menu: true
4
+ sort_info: 8
5
+ ---
6
+ ## News
7
+
8
+ ### 2015-03-12 cmdparse 3.0.0 released!
9
+
10
+ This version is not compatible with previous versions of cmdparse and requires at least Ruby 2.0.
11
+ However, updating code to use the new API is straightforward and the new version offers more
12
+ features!
13
+
14
+ Changes:
15
+
16
+ * License changed to MIT!
17
+ * Top level options and global options are now separated
18
+ * Easier on the fly definition of commands
19
+ * Better help output (automatic formatting of long lines -- even for option descriptions --,
20
+ automatic argument name detection,&nbsp;...)
21
+ * Keyword arguments are now used for better code readability
22
+ * The `CmdParse::VERSION` constant is now a simple version string instead of an array
23
+ * Better API documentation and expanded tutorial
24
+ * Better website design and integration of the API documentation into the website
25
+
26
+
27
+ ### 2014-04-05 cmdparse 2.0.6 released!
28
+
29
+ There were no codewise changes but the used infrastructure and tools have been updated to newer
30
+ versions. Also the license information has been added to the gem specification and the tests are now
31
+ included in the distribution.
32
+
33
+
34
+ ### 2012-06-09 cmdparse 2.0.5 released!
35
+
36
+ Changes:
37
+
38
+ * Fixed backwards incompatible change
39
+
40
+
41
+ ### 2012-06-07 cmdparse 2.0.4 released!
42
+
43
+ Changes:
44
+
45
+ * Only some minor changes regarding the help output for commands which is nicer now.
46
+
47
+
48
+ ### 2006-06-17 cmdparse 2.0.2 released!
49
+
50
+ Changes:
51
+
52
+ * Included two patches from Assaph Mehr:
53
+ * partial command matching can now be used (see the [tutorial page](tutorial.html))
54
+ * now a banner for the help and version commands can be specified
55
+
56
+
57
+ ### 2006-04-05 cmdparse 2.0.1 released!
58
+
59
+ Changes:
60
+
61
+ * Just a bug fix release for those using cmdparse with Rubygems. By issuing the command
62
+ `require_gem 'cmdparse'` the cmdparse library gets automagically loaded.
63
+ * Minor documentation updates
64
+
65
+
66
+ ### 2005-08-16 cmdparse 2.0.0 released!
67
+
68
+ This version is not compatible to previous versions of cmdparse as there have been major changes in
69
+ the API. However, updating your code to use the new API is very easy!
70
+
71
+ Changes:
72
+
73
+ * Commands can now have subcommands which can have subcommands which can have subcommands...
74
+ * No need to implement a whole new class for simple commands anymore
75
+ * Default option parser library is `optparse`, however, any option parser library can be used after writing a small wrapper
76
+
77
+
78
+ ### 2005-07-05 cmdparse 1.0.5 released!
79
+
80
+ Changes:
81
+
82
+ * added possibility to parse global options, command and local options separately
83
+
84
+
85
+ ### 2005-06-16 cmdparse 1.0.4 released!
86
+
87
+ Changes:
88
+
89
+ * fix for older ruby versions
90
+ * fixed bug where exception was not caught
91
+
92
+
93
+ ### 2005-06-09 cmdparse 1.0.3 released!
94
+
95
+ Changes:
96
+
97
+ * added optional graceful exception handling
98
+
99
+
100
+ ### 2005-04-21 cmdparse 1.0.2 released!
101
+
102
+ Changes:
103
+
104
+ * splitted parsing of the arguments and executing the command into two methods
105
+
106
+
107
+ ### 2005-04-13 cmdparse 1.0.1 released!
108
+
109
+ Changes:
110
+
111
+ * Improved HelpCommand: the global options -h and --help take an optional command name now
112
+ * Possibility to define a default command which is used when no command was specified
113
+ * A `NoCommandGivenError` is thrown when no command on the CLI and no default command was specified