Skip to content

Instantly share code, notes, and snippets.

@playupchris
Created June 9, 2011 04:52
Show Gist options
  • Save playupchris/1016087 to your computer and use it in GitHub Desktop.
Save playupchris/1016087 to your computer and use it in GitHub Desktop.
Problems using clamp with explicit subcommand class
#! /usr/bin/env ruby
require 'clamp'
class InitCommand < Clamp::Command
def execute
puts "initializing from another file"
end
end
class MainCommand < Clamp::Command
option '--debug', :flag, "Show stacktraces on error", :default => false
subcommand "init1", "Initialize the repository (from another file)", InitCommand
subcommand "init2", "Initialize the repository (inline)" do
def execute
puts "initializing inline"
end
end
end
MainCommand.run
$ ./explicit_subcommand_class.rb --help
Usage:
explicit_subcommand_class.rb [OPTIONS] SUBCOMMAND [ARGS] ...
Parameters:
SUBCOMMAND subcommand name
[ARGS] ... subcommand arguments
Subcommands:
init1 Initialize the repository (from another file)
init2 Initialize the repository (inline)
Options:
--debug Show stacktraces on error (default: false)
--debug Show stacktraces on error (default: false)
--help print help
$ ./explicit_subcommand_class.rb init1 --help
Usage:
explicit_subcommand_class.rb init1
$ ./explicit_subcommand_class.rb init2 --help
Usage:
explicit_subcommand_class.rb init2 [OPTIONS]
Options:
--debug Show stacktraces on error (default: false)
--help print help
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment