visionmedia-commander 1.2.2 → 2.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.rdoc ADDED
@@ -0,0 +1,85 @@
1
+
2
+ === 2.4.2 / 2009-01-12
3
+
4
+ * Github! build me!
5
+
6
+ === 2.4.1 / 2009-01-11
7
+
8
+ * Added ask_for_CLASS, which may be any class name such as ask_for_date, ask_for_array, etc
9
+ * Changed doc to *.rdoc for pretty markup on github
10
+
11
+ === 2.3.0 / 2008-12-16
12
+
13
+ * Removed input, output in favour of HighLines $terminal
14
+ * Autoloading terminal formatter since it may not always be used
15
+ * Added wrapping of text with 10 padding, defaults to 80
16
+ * Added friendly interruption message by default, overridable with trap or int_message
17
+ * Fixed description now showing as summary when no summary is available
18
+
19
+ === 2.2.1 / 2008-12-09
20
+
21
+ * Fixed typo in String#tokenize, preventing progress bar from working
22
+ * Fixed some small formatting issues with help output
23
+
24
+ === 2.2.0 / 2008-12-09
25
+
26
+ * Additional documentation
27
+ * Added support for arbitrary help 'blocks' using program :help, 'Your block', 'Your blocks contents'
28
+ * Added support for description, summary, short_description, and large_description, which are displaying conditionally within help docs
29
+ * Allowing uncaught exceptions to reach stderr, for debugging purposes
30
+
31
+ === 2.1.1 / 2008-12-01
32
+
33
+ * Changed #password, now requires that the user must enter a non-empty? value
34
+
35
+ === 2.1.0 / 2008-12-01
36
+
37
+ * Added progress bar
38
+ * Added auto-inclusion of FileUtils module
39
+ * Added stdout logging method
40
+ * Fixed issue with options placed before sub-command
41
+
42
+ === 2.0.1 / 2008-11-24
43
+
44
+ * Fixed new line after command options
45
+ * Fixed padding for command list
46
+
47
+ === 2.0.0 / 2008-11-24
48
+
49
+ * Rewrite of entire gem
50
+ * Added auto-parsing and struct population of options
51
+ * Added better documentation
52
+
53
+ === 1.2.2 / 2008-11-06
54
+
55
+ * Forgot to add array.rb
56
+
57
+ === 1.2.0 / 2008-11-06
58
+
59
+ * Added paging ability (similar to 'less')
60
+ * Added coloring to default help generator
61
+
62
+ === 1.1.0 / 2008-11-06
63
+
64
+ * Added dependency for Highline gem, which replaces Commander's user interaction lib
65
+
66
+ === 1.0.4 / 2008-11-04
67
+
68
+ * Added support for --help and --version flags
69
+
70
+ === 1.0.3 / 2008-11-01
71
+
72
+ * Typo causing the gem to fail build on github
73
+
74
+ === 1.0.2 / 2008-11-01
75
+
76
+ * Added gemspec for github
77
+
78
+ === 1.0.1 / 2008-10-31
79
+
80
+ * Added shebang line to commander init
81
+ * Added require 'rubygems'
82
+
83
+ === 1.0.0 / 2008-10-31
84
+
85
+ * Initial release
data/Manifest ADDED
@@ -0,0 +1,33 @@
1
+ bin/commander
2
+ commander.gemspec
3
+ History.rdoc
4
+ lib/commander/command.rb
5
+ lib/commander/core_ext/array.rb
6
+ lib/commander/core_ext/kernel.rb
7
+ lib/commander/core_ext/object.rb
8
+ lib/commander/core_ext/string.rb
9
+ lib/commander/core_ext.rb
10
+ lib/commander/fileutils.rb
11
+ lib/commander/help_formatters/base.rb
12
+ lib/commander/help_formatters/terminal/command_help.erb
13
+ lib/commander/help_formatters/terminal/help.erb
14
+ lib/commander/help_formatters/terminal.rb
15
+ lib/commander/help_formatters.rb
16
+ lib/commander/import.rb
17
+ lib/commander/runner.rb
18
+ lib/commander/user_interaction.rb
19
+ lib/commander/version.rb
20
+ lib/commander.rb
21
+ Manifest
22
+ Rakefile
23
+ README.rdoc
24
+ spec/commander_spec.rb
25
+ spec/help_formatter_spec.rb
26
+ spec/spec_helper.rb
27
+ tasks/docs.rake
28
+ tasks/gemspec.rake
29
+ tasks/spec.rake
30
+ test/fileutils.rb
31
+ test/progress.rb
32
+ test/ui.rb
33
+ Todo.rdoc
data/README.rdoc ADDED
@@ -0,0 +1,178 @@
1
+
2
+ = Commander
3
+
4
+ The complete solution for Ruby command-line executables.
5
+ Commander bridges the gap between other terminal related libraries
6
+ you know and love (OptionParser, HighLine), while providing many new
7
+ features, and an elegant API.
8
+
9
+ == Features:
10
+
11
+ * Easier than baking cookies
12
+ * Parses options using OptionParser
13
+ * Auto-populates struct with options ( no more { |v| options[:recursive] = v } )
14
+ * Auto-generates help documentation via pluggable help formatters
15
+ * Imports the highline gem for interacting with the terminal
16
+ * Adds additional user interaction functionality
17
+ * Highly customizable progress bar with intuative, simple usage
18
+ * Multi-word command name support such as 'drupal module install MOD', rather than 'drupal module_install MOD'
19
+ * Use the 'commander' executable to initialize a commander driven program
20
+
21
+ == Example:
22
+
23
+ For more option examples view the Commander::Command#option method. Also
24
+ an important feature to note is that when_called may be a class to instantiate,
25
+ as well as an object, specifying a method to call, so view the RDoc for more information.
26
+
27
+ require 'rubygems'
28
+ require 'commander'
29
+
30
+ program :name, 'Foo Bar'
31
+ program :version, '1.0.0'
32
+ program :description, 'Stupid command that prints foo or bar.'
33
+
34
+ command :foo do |c|
35
+ c.syntax = "foobar foo"
36
+ c.description = "Displays foo"
37
+ c.when_called do |args, options|
38
+ say "foo"
39
+ end
40
+ end
41
+
42
+ command :bar do |c|
43
+ c.syntax = "foobar [options] bar"
44
+ c.description = "Display bar with optional prefix"
45
+ c.option "--prefix STRING"
46
+ c.when_called do |args, options|
47
+ say "#{options.prefix} bar"
48
+ end
49
+ end
50
+
51
+ == HighLine:
52
+
53
+ As mentioned above the highline gem is imported into 'global scope', below
54
+ are some quick examples for how to utilize highline in your command(s):
55
+
56
+ # Ask for password masked with '*' character
57
+ ask("Password: ") { |q| q.echo = "*" }
58
+
59
+ # Ask for password
60
+ p ask("Password: ") { |q| q.echo = false }
61
+
62
+ # Ask if the user agrees (yes or no)
63
+ agree("Do something?")
64
+
65
+ # Asks on a single line (note the space after ':'
66
+ ask("Name: ")
67
+
68
+ # Asks with new line after "Description:"
69
+ ask("Description:")
70
+
71
+ # Calls Date#parse to parse the date string passed
72
+ ask("Birthday? ", Date)
73
+
74
+ # Ensures Integer is within the range specified
75
+ ask("Age? ", Integer) { |q| q.in = 0..105 }
76
+
77
+ # Asks for a list of strings, converts to array
78
+ ask("Fav colors?", Array)
79
+
80
+ # Provide a menu for users to choose from
81
+ choose do |menu|
82
+ menu.index = :letter
83
+ menu.index_suffix = ") "
84
+ menu.prompt = "Please choose your favorite programming language? "
85
+ menu.choice :ruby do say("Good choice!") end
86
+ menu.choices(:python, :perl) do say("Not from around here, are you?") end
87
+ end
88
+
89
+ # Custom shell
90
+ loop do
91
+ choose do |menu|
92
+ menu.layout = :menu_only
93
+ menu.shell = true
94
+ menu.choice(:load, "Load a file.") do |command, details|
95
+ say("Loading file with options: #{details}...")
96
+ end
97
+ menu.choice(:save, "Save a file.") do |command, details|
98
+ say("Saving file with options: #{details}...")
99
+ end
100
+ menu.choice(:quit, "Exit program.") { exit }
101
+ end
102
+ end
103
+
104
+ == HighLine & Interaction Additions:
105
+
106
+ In addition to highline's fantastic choice of methods we will continue to
107
+ simplify common tasks using the following methods:
108
+
109
+ # Ask for password
110
+ password
111
+
112
+ # Ask for password with specific message and mask character
113
+ password "Enter your password please:", '-'
114
+
115
+ # Ask for CLASS, which may be any valid class responding to #parse. Date, Time, Array, etc
116
+ names = ask_for_array 'Names: '
117
+ bday = ask_for_date 'Birthday?: '
118
+
119
+ # Simple progress bar (Commander::UI::ProgressBar)
120
+ uris = %w[
121
+ http://vision-media.ca
122
+ http://google.com
123
+ http://yahoo.com
124
+ ]
125
+ progress uris do |uri|
126
+ res = open uri
127
+ # Do something with response
128
+ end
129
+
130
+ # 'Log' action to stdout
131
+ log "create", "path/to/file.rb"
132
+
133
+ == FileUtils:
134
+
135
+ The VerboseFileUtils module is automatically included within the main object for
136
+ global usage. These will output 'log' messages such as:
137
+
138
+ remove doc
139
+ create path
140
+ create path/to/file.rb
141
+ move path/to/something path/to/destination
142
+
143
+ If you do not wish to use FileUtils in a verbose manor simply call FileUtil's
144
+ methods directly.
145
+
146
+ == ASCII Tables
147
+
148
+ For feature rich ASCII tables for your terminal app check out visionmedia's terminal-table gem at
149
+ http://github.com/visionmedia/terminal-table
150
+
151
+ == Known Issues:
152
+
153
+ * none
154
+
155
+ == LICENSE:
156
+
157
+ (The MIT License)
158
+
159
+ Copyright (c) 2008 TJ Holowaychuk <tj@vision-media.ca>
160
+
161
+ Permission is hereby granted, free of charge, to any person obtaining
162
+ a copy of this software and associated documentation files (the
163
+ 'Software'), to deal in the Software without restriction, including
164
+ without limitation the rights to use, copy, modify, merge, publish,
165
+ distribute, sublicense, and/or sell copies of the Software, and to
166
+ permit persons to whom the Software is furnished to do so, subject to
167
+ the following conditions:
168
+
169
+ The above copyright notice and this permission notice shall be
170
+ included in all copies or substantial portions of the Software.
171
+
172
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
173
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
174
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
175
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
176
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
177
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
178
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,34 +1,12 @@
1
- # -*- ruby -*-
2
1
 
3
- require 'rubygems'
4
- require 'hoe'
5
- require './lib/commander.rb'
2
+ %w( rubygems rake echoe ./lib/commander.rb ).each { |lib| require lib }
6
3
 
7
- Hoe.new('commander', Commander::VERSION) do |p|
8
- p.developer('TJ Holowaychuk', 'tj@vision-media.ca')
9
- p.extra_deps << ['highline', '>= 1.5.0']
4
+ Echoe.new("commander", Commander::VERSION::STRING) do |p|
5
+ p.author = "TJ Holowaychuk"
6
+ p.email = "tj@vision-media.ca"
7
+ p.summary = "The complete solution for Ruby command-line executables"
8
+ p.url = "http://github.com/visionmedia/commander"
9
+ p.runtime_dependencies = ["highline >=1.5.0"]
10
10
  end
11
11
 
12
- desc 'Build and install gem.'
13
- task :build => [:remove, :install_gem] do
14
- sh "clear"
15
- end
16
-
17
- desc 'Remove build data.'
18
- task :remove => [:clean] do
19
- sh "clear"
20
- end
21
-
22
- desc 'Run rspec suite.'
23
- task :spec do
24
- sh "clear"
25
- sh "spec ./spec/all_spec.rb"
26
- end
27
-
28
- desc 'Run rspec suite with specdoc format.'
29
- task :specd do
30
- sh "clear"
31
- sh "spec ./spec/all_spec.rb --format specdoc"
32
- end
33
-
34
- # vim: syntax=Ruby
12
+ Dir['tasks/**/*.rake'].sort.each { |lib| load lib }
data/Todo.rdoc ADDED
@@ -0,0 +1,12 @@
1
+
2
+ * Release to RubyForge as well
3
+ * Fix excessive Dir#[] calls due to rubygems, http://rubyforge.org/tracker/index.php?func=detail&aid=23170&group_id=126&atid=575
4
+ * Change; Have VerboseFileUtils only output basename ?
5
+ * Add highline paging ... clean it up
6
+ * Add global options... change runner implementations as well as displaying in terminal formatter, OpenStruct inherit these options?
7
+ * Add global --options switch for loading options from a filepath
8
+ * Add; dynamically generate padding erb templates, command lists, multi-line text bodies etc
9
+ * Add; display global options with global help
10
+ * Change; consider reversing |options, args| so args can be |options, file, dir| etc.. adjust doc
11
+ * Change; refactor specs
12
+ * Publish rdoc
data/bin/commander CHANGED
@@ -1,55 +1,52 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'rubygems'
3
4
  require 'commander'
4
5
 
5
- init_commander(
6
- :name => 'Commander',
7
- :version => Commander::VERSION,
8
- :description => 'Commander utility program.'
9
- )
6
+ program :name, 'commander'
7
+ program :version, Commander::VERSION::STRING
8
+ program :description, 'Commander utility program.'
10
9
 
11
10
  command :init do |c|
12
- c.syntax = 'commander init <filepath>'
13
- c.description = 'Initialize an empty file with a commander skeleton.'
14
- c.example 'Create a new file with a commander skeleton.', 'commander init ./bin/my_executable'
15
- c.when_called do |args|
11
+ c.syntax = 'commander init <file>'
12
+ c.summary = 'Initialize a commander template'
13
+ c.description = 'Initialize an empty file with a commander template, allowing extremely quick creation of commader executables.'
14
+ c.example 'Create a new file with a commander template.', 'commander init ./bin/my_executable'
15
+ c.when_called do |args, options|
16
16
  abort "Provide a filepath." if args.empty?
17
- puts
18
- name = ask 'What is your programs machine name?'
19
- description = ask 'Describe your program:'
20
- commands = ask 'List the sub-commands you wish to create:', Array
17
+ name = ask 'Machine name of program: '
18
+ description = ask 'Describe your program: '
19
+ commands = ask 'List the sub-commands you wish to create: ', Array
21
20
  begin
22
- filepath = args.shift
23
- File.open(filepath, 'w') do |f|
21
+ File.open(args.first, 'w') do |f|
24
22
  f.write <<-CODE
25
23
  #!/usr/bin/env ruby
26
24
 
27
25
  require 'rubygems'
28
26
  require 'commander'
27
+ require '#{name}'
29
28
 
30
- init_commander(
31
- :name => '#{name.capitalize}',
32
- :version => #{name.capitalize}::VERSION,
33
- :description => '#{description}'
34
- )
35
-
29
+ program :name, '#{name}'
30
+ program :version, #{name.camelcase}::VERSION::STRING
31
+ program :description, '#{description}.'
32
+
36
33
  CODE
37
34
  commands.each do |command|
38
35
  f.write <<-CODE
39
36
  command :#{command} do |c|
40
37
  c.syntax = ''
41
38
  c.description = ''
42
- c.example 'description', 'code'
43
- c.when_called do |args|
44
- # Do something
39
+ c.example 'description', 'command example'
40
+ c.option '--some-switch', 'Some switch that does something'
41
+ c.when_called do |args, options|
42
+ # Do something or c.when_called #{name.camelcase}::Commands::#{command.camelcase}
45
43
  end
46
44
  end
47
45
 
48
46
  CODE
49
47
  end
50
48
  end
51
- say "Created commander skeleton at '#{filepath}'."
52
- puts
49
+ say "Initialized template in #{args.first}"
53
50
  rescue Exception => e
54
51
  abort e
55
52
  end
data/commander.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{commander}
5
+ s.version = "2.4.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["TJ Holowaychuk"]
9
+ s.date = %q{2009-01-12}
10
+ s.default_executable = %q{commander}
11
+ s.description = %q{The complete solution for Ruby command-line executables}
12
+ s.email = %q{tj@vision-media.ca}
13
+ s.executables = ["commander"]
14
+ s.extra_rdoc_files = ["bin/commander", "lib/commander/command.rb", "lib/commander/core_ext/array.rb", "lib/commander/core_ext/kernel.rb", "lib/commander/core_ext/object.rb", "lib/commander/core_ext/string.rb", "lib/commander/core_ext.rb", "lib/commander/fileutils.rb", "lib/commander/help_formatters/base.rb", "lib/commander/help_formatters/terminal/command_help.erb", "lib/commander/help_formatters/terminal/help.erb", "lib/commander/help_formatters/terminal.rb", "lib/commander/help_formatters.rb", "lib/commander/import.rb", "lib/commander/runner.rb", "lib/commander/user_interaction.rb", "lib/commander/version.rb", "lib/commander.rb", "README.rdoc", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
15
+ s.files = ["bin/commander", "commander.gemspec", "History.rdoc", "lib/commander/command.rb", "lib/commander/core_ext/array.rb", "lib/commander/core_ext/kernel.rb", "lib/commander/core_ext/object.rb", "lib/commander/core_ext/string.rb", "lib/commander/core_ext.rb", "lib/commander/fileutils.rb", "lib/commander/help_formatters/base.rb", "lib/commander/help_formatters/terminal/command_help.erb", "lib/commander/help_formatters/terminal/help.erb", "lib/commander/help_formatters/terminal.rb", "lib/commander/help_formatters.rb", "lib/commander/import.rb", "lib/commander/runner.rb", "lib/commander/user_interaction.rb", "lib/commander/version.rb", "lib/commander.rb", "Manifest", "Rakefile", "README.rdoc", "spec/commander_spec.rb", "spec/help_formatter_spec.rb", "spec/spec_helper.rb", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake", "test/fileutils.rb", "test/progress.rb", "test/ui.rb", "Todo.rdoc"]
16
+ s.has_rdoc = true
17
+ s.homepage = %q{http://github.com/visionmedia/commander}
18
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Commander", "--main", "README.rdoc"]
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{commander}
21
+ s.rubygems_version = %q{1.3.1}
22
+ s.summary = %q{The complete solution for Ruby command-line executables}
23
+
24
+ if s.respond_to? :specification_version then
25
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
+ s.specification_version = 2
27
+
28
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
29
+ s.add_runtime_dependency(%q<highline>, [">= 1.5.0"])
30
+ s.add_development_dependency(%q<echoe>, [">= 0"])
31
+ else
32
+ s.add_dependency(%q<highline>, [">= 1.5.0"])
33
+ s.add_dependency(%q<echoe>, [">= 0"])
34
+ end
35
+ else
36
+ s.add_dependency(%q<highline>, [">= 1.5.0"])
37
+ s.add_dependency(%q<echoe>, [">= 0"])
38
+ end
39
+ end