delano-drydock 0.6.3 → 0.6.5

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/CHANGES.txt CHANGED
@@ -5,6 +5,12 @@ DRYDOCK, CHANGES
5
5
  * Support putting descriptions into resource file (or __END__)
6
6
 
7
7
 
8
+ #### 0.6.5 (2009-05-21) #############################
9
+
10
+ * ADDED: "with_args" support for default command. When specified,
11
+ arguments can be passed to the default command with run in the
12
+ short form. e.g. "script arg1 arg2" == "script cmdname arg1 arg2"
13
+
8
14
  #### 0.6.3 (2009-05-10) #############################
9
15
 
10
16
  * ADDED: show-commands now displays a note about which command is the default
data/README.rdoc CHANGED
@@ -31,7 +31,7 @@ See bin/example for more.
31
31
  # variables defined here will be available to all commands.
32
32
  end
33
33
 
34
- desc "A friendly welcome to the Drydock"
34
+ about "A friendly welcome to the Drydock"
35
35
  command :welcome do
36
36
  puts "Welcome to Drydock."
37
37
  puts "For available commands:"
@@ -39,7 +39,7 @@ See bin/example for more.
39
39
  end
40
40
 
41
41
  usage "USAGE: #{$0} laugh [-f]"
42
- desc "The captain commands his crew to laugh"
42
+ about "The captain commands his crew to laugh"
43
43
  option :f, :faster, "A boolean value. Go even faster!"
44
44
  command :laugh do |obj|
45
45
  # +obj+ is an instance of Drydock::Command. The options you define are available
@@ -58,12 +58,12 @@ See bin/example for more.
58
58
  def ahoy!; p "matey"; end
59
59
  end
60
60
 
61
- desc "Do something with John West's Smoked Oysters"
61
+ about "Do something with John West's Smoked Oysters"
62
62
  command :oysters => JohnWestSmokedOysters do |obj|
63
63
  p obj # => #<JohnWestSmokedOysters:0x42179c ... >
64
64
  end
65
65
 
66
- desc "My way of saying hello!"
66
+ about "My way of saying hello!"
67
67
  command :ahoy! => JohnWestSmokedOysters
68
68
  # If you don't provide a block, Drydock will call JohnWestSmokedOysters#ahoy!
69
69
 
data/drydock.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  @spec = Gem::Specification.new do |s|
2
2
  s.name = %q{drydock}
3
- s.version = "0.6.3"
3
+ s.version = "0.6.5"
4
4
  s.specification_version = 1 if s.respond_to? :specification_version=
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
6
 
data/lib/drydock.rb CHANGED
@@ -371,6 +371,7 @@ module Drydock
371
371
  @@command_actions = []
372
372
 
373
373
  @@default_command = nil
374
+ @@default_command_with_args = false
374
375
 
375
376
  @@commands = {}
376
377
  @@command_descriptions = []
@@ -455,10 +456,19 @@ module Drydock
455
456
  # # ...
456
457
  # end
457
458
  #
458
- def default(cmd=nil, &b)
459
+ # If +with_args+ is specified, the default command will receive all unknown
460
+ # values as arguments. This is necessary to define explicitly because drydock
461
+ # parses arguments expecting a command name. If the default command accepts
462
+ # arguments and with_args is not specified, drydock will raise an unknown
463
+ # command exception for the first argument.
464
+ #
465
+ def default(cmd=nil, with_args=false, &b)
459
466
  raise "Calling default requires a command name or a block" unless cmd || b
460
467
  # Creates the command and returns the name or just stores given name
461
468
  @@default_command = (b) ? command(cmd || :default, &b).cmd : canonize(cmd)
469
+ # IDEA: refactor out the argument parser to support different types of CLI
470
+ @@default_command_with_args = with_args ? true : false
471
+ @@default_command
462
472
  end
463
473
 
464
474
  # Is +cmd+ the default command?
@@ -467,6 +477,10 @@ module Drydock
467
477
  (@@default_command == canonize(cmd))
468
478
  end
469
479
 
480
+ #
481
+ def default_with_args?; @@default_command_with_args; end
482
+
483
+
470
484
  # Define a block for processing STDIN before the command is called.
471
485
  # The command block receives the return value of this block as obj.stdin:
472
486
  #
@@ -844,13 +858,21 @@ module Drydock
844
858
  global_options = command_options = {}
845
859
  cmd = nil
846
860
 
861
+ argv_copy = argv.clone # See: @@default_command_with_args below
862
+
847
863
  global_options = @@global_opts_parser.getopts(argv)
848
864
  cmd_name = (argv.empty?) ? @@default_command : argv.shift
849
865
 
850
866
  unless command?(cmd_name)
851
- raise UnknownCommand.new(cmd_name) unless trawler?
852
- raise UnknownCommand.new(@@trawler) unless command?(@@trawler)
853
- command_alias(@@trawler, cmd_name)
867
+ # If requested, send all unknown arguments to the default command
868
+ if @@default_command_with_args
869
+ cmd_name = @@default_command
870
+ argv = argv_copy
871
+ else
872
+ raise UnknownCommand.new(cmd_name) unless trawler?
873
+ raise UnknownCommand.new(@@trawler) unless command?(@@trawler)
874
+ command_alias(@@trawler, cmd_name)
875
+ end
854
876
  end
855
877
 
856
878
  cmd = get_command(cmd_name)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delano-drydock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-08 00:00:00 -07:00
12
+ date: 2009-05-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15