Class: RightDevelop::Commands::Git
- Inherits:
-
Object
- Object
- RightDevelop::Commands::Git
- Defined in:
- lib/right_develop/commands/git.rb
Constant Summary collapse
- NAME_SPLIT_CHARS =
/-|_|\//- YES =
/(ye?s?)/i- NO =
/(no?)/i- TASKS =
%w(prune)
Class Method Summary collapse
-
.create ⇒ Object
Parse command-line options and create a Command object.
Instance Method Summary collapse
-
#initialize(repo, task, options) ⇒ Git
constructor
A new instance of Git.
-
#run ⇒ Object
Run the task that was specified when this object was instantiated.
Constructor Details
#initialize(repo, task, options) ⇒ Git
Returns a new instance of Git.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/right_develop/commands/git.rb', line 86 def initialize(repo, task, ) # Post-process "age" option; transform from natural-language expression into a timestamp. if (age = .delete(:age)) require 'ruby-debug' debugger age = parse_age(age) [:age] = age end # Post-process "except" option; transform into a Regexp. if (except = .delete(:except)) except = Regexp.new("^(origin/)?(#{except})") [:except] = except end # Post-process "only" option; transform into a Regexp. if (only = .delete(:only)) only = Regexp.new("^(origin/)?(#{only})") [:only] = only end @git = repo @task = task = end |
Class Method Details
.create ⇒ Object
Parse command-line options and create a Command object
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 71 72 73 74 75 76 77 78 |
# File 'lib/right_develop/commands/git.rb', line 36 def self.create task_list = TASKS.map { |c| " * #{c}" }.join("\n") = Trollop. do "The 'git' command automates various repository management tasks. All tasks\naccept the same options, although not every option applies to every command.\n\nUsage:\n right_develop git <task> [options]\n\nWhere <task> is one of:\n\#{task_list}\n\nAnd [options] are selected from:\n" opt :age, "Minimum age to consider", :default => "3.months" opt :only, "Limit to branches matching this prefix", :type=>:string opt :except, "Ignore branches matching this prefix", :type=>:string, :default => "^(release|v?[0-9.]+|)" opt :local, "Limit to local branches" opt :remote, "Limit to remote branches" opt :merged, "Limit to branches that are fully merged into the named branch", :type=>:string, :default => "master" stop_on TASKS end task = ARGV.shift case task when "prune" repo = ::RightGit::Git::Repository.new( ::Dir.pwd, ::RightDevelop::Utility::Git::DEFAULT_REPO_OPTIONS) self.new(repo, :prune, ) else Trollop.die "unknown task #{task}" end end |
Instance Method Details
#run ⇒ Object
Run the task that was specified when this object was instantiated. This method does no work; it just delegates to a task method.
114 115 116 117 118 119 120 121 |
# File 'lib/right_develop/commands/git.rb', line 114 def run case @task when :prune prune() else raise StateError, "Invalid @task; check Git.create!" end end |