1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#! /usr/bin/env ruby
# Demonstrate how subcommands can be declared as classes
require "clamp"
module GitDown
class AbstractCommand < Clamp::Command
option ["-v", "--verbose"], :flag, "be verbose"
option "--version", :flag, "show version" do
puts "GitDown-0.0.0a"
exit(0)
end
def say(message)
message = message.upcase if verbose?
puts message
end
end
class CloneCommand < AbstractCommand
parameter "REPOSITORY", "repository to clone"
parameter "[DIR]", "working directory", :default => "."
def execute
say "cloning to #{dir}"
end
end
class PullCommand < AbstractCommand
option "--[no-]commit", :flag, "Perform the merge and commit the result."
def execute
say "pulling"
end
end
class StatusCommand < AbstractCommand
option ["-s", "--short"], :flag, "Give the output in the short-format."
def execute
if short?
say "good"
else
say "it's all good ..."
end
end
end
class MainCommand < AbstractCommand
subcommand "clone", "Clone a remote repository.", CloneCommand
subcommand "pull", "Fetch and merge updates.", PullCommand
subcommand "status", "Display status of local repository.", StatusCommand
end
end
GitDown::MainCommand.run
|