cmdparse 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +340 -0
- data/ChangeLog +80 -0
- data/README +52 -0
- data/Rakefile +207 -0
- data/TODO +5 -0
- data/VERSION +1 -0
- data/doc/src/default.css +137 -0
- data/doc/src/default.template +32 -0
- data/doc/src/download.fragment +32 -0
- data/doc/src/features.fragment +8 -0
- data/doc/src/index.fragment +21 -0
- data/doc/src/metainfo.backing +25 -0
- data/lib/cmdparse.rb +305 -0
- data/setup.rb +1331 -0
- metadata +53 -0
data/Rakefile
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
#
|
3
|
+
# $Id$
|
4
|
+
#
|
5
|
+
# cmdparse: an advanced command line parser using optparse which supports commands
|
6
|
+
# Copyright (C) 2004 Thomas Leitner
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or modify it under the terms of the GNU
|
9
|
+
# General Public License as published by the Free Software Foundation; either version 2 of the
|
10
|
+
# License, or (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
13
|
+
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License along with this program; if not,
|
17
|
+
# write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18
|
+
#
|
19
|
+
|
20
|
+
|
21
|
+
begin
|
22
|
+
require 'rubygems'
|
23
|
+
require 'rake/gempackagetask'
|
24
|
+
rescue Exception
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'rake/clean'
|
29
|
+
require 'rake/packagetask'
|
30
|
+
require 'rake/rdoctask'
|
31
|
+
require 'rake/testtask'
|
32
|
+
|
33
|
+
# General actions ##############################################################
|
34
|
+
|
35
|
+
require 'lib/cmdparse'
|
36
|
+
|
37
|
+
PKG_NAME = "cmdparse"
|
38
|
+
PKG_VERSION = CommandParser::VERSION.join( '.' )
|
39
|
+
PKG_FULLNAME = PKG_NAME + "-" + PKG_VERSION
|
40
|
+
|
41
|
+
SRC_RB = FileList['lib/**/*.rb']
|
42
|
+
|
43
|
+
# The default task is run if rake is given no explicit arguments.
|
44
|
+
|
45
|
+
desc "Default Task"
|
46
|
+
task :default => :doc
|
47
|
+
|
48
|
+
|
49
|
+
# End user tasks ################################################################
|
50
|
+
|
51
|
+
desc "Prepares for installation"
|
52
|
+
task :prepare do
|
53
|
+
ruby "setup.rb config"
|
54
|
+
ruby "setup.rb setup"
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
desc "Installs the package #{PKG_NAME}"
|
59
|
+
task :install => [:prepare]
|
60
|
+
task :install do
|
61
|
+
ruby "setup.rb install"
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
task :clean do
|
66
|
+
ruby "setup.rb clean"
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
CLOBBER << "doc/output"
|
71
|
+
desc "Builds the documentation"
|
72
|
+
task :doc => [:rdoc] do
|
73
|
+
Dir.chdir("doc")
|
74
|
+
sh "webgen -V 4"
|
75
|
+
Dir.chdir("..")
|
76
|
+
end
|
77
|
+
|
78
|
+
rd = Rake::RDocTask.new do |rdoc|
|
79
|
+
rdoc.rdoc_dir = 'doc/output/rdoc'
|
80
|
+
rdoc.title = PKG_NAME
|
81
|
+
rdoc.options << '--line-numbers' << '--inline-source' << '-m README'
|
82
|
+
rdoc.rdoc_files.include( 'README' )
|
83
|
+
rdoc.rdoc_files.include( 'lib/**/*.rb' )
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
# Developer tasks ##############################################################
|
88
|
+
|
89
|
+
|
90
|
+
PKG_FILES = FileList.new( [
|
91
|
+
'setup.rb',
|
92
|
+
'TODO',
|
93
|
+
'COPYING',
|
94
|
+
'README',
|
95
|
+
'Rakefile',
|
96
|
+
'ChangeLog',
|
97
|
+
'VERSION',
|
98
|
+
'lib/**/*.rb',
|
99
|
+
'doc/**/*'
|
100
|
+
]) do |fl|
|
101
|
+
fl.exclude( /\bsvn\b/ )
|
102
|
+
fl.exclude( 'doc/output' )
|
103
|
+
end
|
104
|
+
|
105
|
+
if !defined? Gem
|
106
|
+
puts "Package Target requires RubyGEMs"
|
107
|
+
else
|
108
|
+
spec = Gem::Specification.new do |s|
|
109
|
+
|
110
|
+
#### Basic information
|
111
|
+
|
112
|
+
s.name = PKG_NAME
|
113
|
+
s.version = PKG_VERSION
|
114
|
+
s.summary = "An advanced command line parser using optparse which supports commands"
|
115
|
+
s.description = <<-EOF
|
116
|
+
cmdparse extends the default option parser 'optparse' by adding
|
117
|
+
support for commands. Programs that use such command line interfaces
|
118
|
+
are, for example, subversion's 'svn' or Rubygem's 'gem' program.
|
119
|
+
EOF
|
120
|
+
|
121
|
+
#### Dependencies, requirements and files
|
122
|
+
|
123
|
+
s.files = PKG_FILES.to_a
|
124
|
+
|
125
|
+
s.require_path = 'lib'
|
126
|
+
s.autorequire = nil
|
127
|
+
|
128
|
+
#### Documentation
|
129
|
+
|
130
|
+
s.has_rdoc = true
|
131
|
+
s.extra_rdoc_files = rd.rdoc_files.reject do |fn| fn =~ /\.rb$/ end.to_a
|
132
|
+
s.rdoc_options = ['--line-numbers', '-m README']
|
133
|
+
|
134
|
+
#### Author and project details
|
135
|
+
|
136
|
+
s.author = "Thomas Leitner"
|
137
|
+
s.email = "t_leitner@gmx.at"
|
138
|
+
s.homepage = "cmdparse.rubyforge.org"
|
139
|
+
s.rubyforge_project = "cmdparse"
|
140
|
+
end
|
141
|
+
|
142
|
+
task :package => [:generateFiles]
|
143
|
+
task :generateFiles do |t|
|
144
|
+
sh "svn log -r HEAD:1 -v > ChangeLog"
|
145
|
+
File.open('VERSION', 'w+') do |file| file.write( PKG_VERSION + "\n" ) end
|
146
|
+
end
|
147
|
+
|
148
|
+
CLOBBER << "ChangeLog" << "VERSION"
|
149
|
+
|
150
|
+
Rake::GemPackageTask.new( spec ) do |pkg|
|
151
|
+
pkg.need_zip = true
|
152
|
+
pkg.need_tar = true
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
desc "Creates a tag in the repository"
|
159
|
+
task :tag do
|
160
|
+
repositoryPath = File.dirname( $1 ) if `svn info` =~ /^URL: (.*)$/
|
161
|
+
fail "Tag already created in repository " if /#{PKG_FULLNAME}/ =~ `svn ls #{repositoryPath}/versions`
|
162
|
+
sh "svn cp -m 'Created version #{PKG_FULLNAME}' #{repositoryPath}/trunk #{repositoryPath}/versions/#{PKG_FULLNAME}"
|
163
|
+
end
|
164
|
+
|
165
|
+
desc "Upload documentation to homepage"
|
166
|
+
task :uploaddoc => [:doc] do
|
167
|
+
Dir.chdir('doc/output')
|
168
|
+
sh "scp -r * gettalong@rubyforge.org:/var/www/gforge-projects/cmdparse/"
|
169
|
+
end
|
170
|
+
|
171
|
+
|
172
|
+
# Misc tasks ###################################################################
|
173
|
+
|
174
|
+
|
175
|
+
def count_lines( filename )
|
176
|
+
lines = 0
|
177
|
+
codelines = 0
|
178
|
+
open( filename ) do |f|
|
179
|
+
f.each do |line|
|
180
|
+
lines += 1
|
181
|
+
next if line =~ /^\s*$/
|
182
|
+
next if line =~ /^\s*#/
|
183
|
+
codelines += 1
|
184
|
+
end
|
185
|
+
end
|
186
|
+
[lines, codelines]
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
def show_line( msg, lines, loc )
|
191
|
+
printf "%6s %6s %s\n", lines.to_s, loc.to_s, msg
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
desc "Show statistics"
|
196
|
+
task :statistics do
|
197
|
+
total_lines = 0
|
198
|
+
total_code = 0
|
199
|
+
show_line( "File Name", "Lines", "LOC" )
|
200
|
+
SRC_RB.each do |fn|
|
201
|
+
lines, codelines = count_lines fn
|
202
|
+
show_line( fn, lines, codelines )
|
203
|
+
total_lines += lines
|
204
|
+
total_code += codelines
|
205
|
+
end
|
206
|
+
show_line( "Total", total_lines, total_code )
|
207
|
+
end
|
data/TODO
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/doc/src/default.css
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
html {
|
2
|
+
margin: 0px 5%;
|
3
|
+
background-color: #eee;
|
4
|
+
}
|
5
|
+
|
6
|
+
body {
|
7
|
+
margin: 0px;
|
8
|
+
padding: 0px;
|
9
|
+
background-color: #fff;
|
10
|
+
font-size: 12px;
|
11
|
+
font-family: Verdana, Arial, Helvetica;
|
12
|
+
}
|
13
|
+
|
14
|
+
/* General layout of the page */
|
15
|
+
|
16
|
+
#header, #footer {
|
17
|
+
width: 100%;
|
18
|
+
background-color: #58b;
|
19
|
+
color: #fff;
|
20
|
+
}
|
21
|
+
|
22
|
+
#menu {
|
23
|
+
float: left;
|
24
|
+
width: 230px;
|
25
|
+
padding: 20px 0px 0px 20px;
|
26
|
+
border: 3px solid #58b;
|
27
|
+
}
|
28
|
+
|
29
|
+
#body {
|
30
|
+
margin-left: 250px;
|
31
|
+
padding: 20px;
|
32
|
+
}
|
33
|
+
|
34
|
+
#footer {
|
35
|
+
clear: both;
|
36
|
+
padding: 5px 0px;
|
37
|
+
text-align: center;
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
/* styling the header */
|
42
|
+
|
43
|
+
#headerbar {
|
44
|
+
width: 100%;
|
45
|
+
font-size: 90%;
|
46
|
+
}
|
47
|
+
|
48
|
+
span#navbar, span#languages {
|
49
|
+
padding: 3px;
|
50
|
+
width: 45%;
|
51
|
+
}
|
52
|
+
|
53
|
+
span#navbar {
|
54
|
+
float: left;
|
55
|
+
text-align: left;
|
56
|
+
}
|
57
|
+
|
58
|
+
span#languages {
|
59
|
+
float: right;
|
60
|
+
text-align: right;
|
61
|
+
}
|
62
|
+
|
63
|
+
div#header h1, h2 {
|
64
|
+
margin: 0px;
|
65
|
+
padding: 15px 50px 0px;
|
66
|
+
|
67
|
+
font-size: 300%;
|
68
|
+
font-style: italic;
|
69
|
+
font-weight: normal;
|
70
|
+
}
|
71
|
+
|
72
|
+
div#header h2 {
|
73
|
+
padding-top: 0px;
|
74
|
+
padding-bottom: 15px;
|
75
|
+
font-size: 100%;
|
76
|
+
}
|
77
|
+
|
78
|
+
/* styling the menu */
|
79
|
+
|
80
|
+
#menu a {
|
81
|
+
text-decoration: none;
|
82
|
+
color: #b55;
|
83
|
+
font-weight: bold;
|
84
|
+
font-size: 130%;
|
85
|
+
}
|
86
|
+
|
87
|
+
#menu a:hover {
|
88
|
+
text-decoration: underline;
|
89
|
+
}
|
90
|
+
|
91
|
+
#menu .webgen-menuitem-selected {
|
92
|
+
border-left: 3px solid #58b;
|
93
|
+
}
|
94
|
+
|
95
|
+
#menu .webgen-submenu {
|
96
|
+
}
|
97
|
+
|
98
|
+
#menu ul {
|
99
|
+
list-style-type: none;
|
100
|
+
padding: 0px;
|
101
|
+
margin-left: 10px;
|
102
|
+
}
|
103
|
+
|
104
|
+
#menu li > ul {
|
105
|
+
font-size: 95%;
|
106
|
+
}
|
107
|
+
|
108
|
+
#menu li {
|
109
|
+
margin: 0.0em 0px;
|
110
|
+
padding: 2px 0px;
|
111
|
+
padding-left: 5px;
|
112
|
+
border-left: 3px solid #CCCCCC;
|
113
|
+
}
|
114
|
+
|
115
|
+
/* styling the content */
|
116
|
+
|
117
|
+
div.section {
|
118
|
+
margin-bottom: 30px;
|
119
|
+
}
|
120
|
+
|
121
|
+
h2.section_header {
|
122
|
+
padding: 0px;
|
123
|
+
border-bottom: 3px double #8b5;
|
124
|
+
|
125
|
+
letter-spacing: 0.2em;
|
126
|
+
font-size: 150%;
|
127
|
+
font-weight: bold;
|
128
|
+
color: #8b5;
|
129
|
+
}
|
130
|
+
|
131
|
+
pre.webgen-file {
|
132
|
+
padding-left: 10px;
|
133
|
+
margin: 0px 10px;
|
134
|
+
border-left: 3px solid #8b5;
|
135
|
+
}
|
136
|
+
|
137
|
+
}
|
@@ -0,0 +1,32 @@
|
|
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="en">
|
4
|
+
<head>
|
5
|
+
<title>CommandParser: {title: }</title>
|
6
|
+
<link href="{relocatable: default.css}" rel="stylesheet" />
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<div id="header">
|
10
|
+
<h1>{title: }</h1>
|
11
|
+
<h2>cmdparse: an advanced command line parser using optparse which supports commands</h2>
|
12
|
+
<div id="headerbar">
|
13
|
+
<span id="navbar">{navbar: }</span>
|
14
|
+
<span id="languages">{lang: }</span>
|
15
|
+
<div style="clear: both; border-top: 1px solid #58b"></div>
|
16
|
+
</div>
|
17
|
+
</div>
|
18
|
+
|
19
|
+
<div id="menu">
|
20
|
+
{menu: }
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<div id="body">
|
24
|
+
{content: }
|
25
|
+
</div>
|
26
|
+
|
27
|
+
<div id="footer">
|
28
|
+
generated with <em><b><a href="http://webgen.rubyforge.org">webgen</a></b></em> on <b>{date: }</b>
|
29
|
+
</div>
|
30
|
+
|
31
|
+
</body>
|
32
|
+
</html>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<div class="section">
|
2
|
+
<h2 class="section_header">Download</h2>
|
3
|
+
<p>The newest version of cmdparse can be downloaded from Rubyforge.</p>
|
4
|
+
<p>Homepage: <a href="http://cmdparse.rubyforge.org">cmdparse.rubyforge.org</a><br />
|
5
|
+
Download: <a href="http://rubyforge.org/frs/?group_id=396">http://rubyforge.org/frs/?group_id=396</a>
|
6
|
+
</p>
|
7
|
+
</div>
|
8
|
+
|
9
|
+
<div class="section">
|
10
|
+
<h2 class="section_header">Dependencies</h2>
|
11
|
+
<p>optparse - part of the standard ruby distribution, so nothing to do here</p>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div class="section">
|
15
|
+
<h2 class="section_header">Installation</h2>
|
16
|
+
You can use the standard way to install cmdparse:
|
17
|
+
<pre>
|
18
|
+
$ ruby setup.rb config
|
19
|
+
$ ruby setup.rb setup
|
20
|
+
$ ruby setup.rb install
|
21
|
+
</pre>
|
22
|
+
|
23
|
+
Or you could use Rake and substitute the above commands with this:
|
24
|
+
<pre>
|
25
|
+
$ rake install
|
26
|
+
</pre>
|
27
|
+
|
28
|
+
Or you could install cmdparse the "GEM way":
|
29
|
+
<pre>
|
30
|
+
$ gem install cmdparse
|
31
|
+
</pre>
|
32
|
+
</div>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<div class="section">
|
2
|
+
<h2 class="section_header">Feature list</h2>
|
3
|
+
<ul>
|
4
|
+
<li>Based upon the standard library <code>optparse</code></li>
|
5
|
+
<li>Each command is implemented via a class</li>
|
6
|
+
<li>As easy to use as <code>optparse</code> itself</li>
|
7
|
+
</ul>
|
8
|
+
</div>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<div class="section">
|
2
|
+
<h2 class="section_header">Welcome</h2>
|
3
|
+
<p>... to the homepage of <i><b>cmdparse</b></i>, an advanced command line parser.</p>
|
4
|
+
<p>Have a look around the site!</p>
|
5
|
+
</div>
|
6
|
+
|
7
|
+
<div class="section">
|
8
|
+
<h2 class="section_header">Description</h2>
|
9
|
+
<p>Some new programs use a "command style" command line. Examples for such programs are the "svn"
|
10
|
+
program from Subversion and the "gem" program from Rubygems. The standard Ruby distribution has no
|
11
|
+
library to create programs that use such a command line interface.</p>
|
12
|
+
|
13
|
+
<p>This library, cmdparse, can be used to create such a command line interface. Internally it uses
|
14
|
+
optparse to parse options and it provides a nice API for specifying commands.</p>
|
15
|
+
|
16
|
+
</div>
|
17
|
+
|
18
|
+
<div class="section">
|
19
|
+
<h2 class="section_header">And so ...</h2>
|
20
|
+
<p>... have fun!</p>
|
21
|
+
</div>
|