Class: RightDevelop::Commands::Git
- Inherits:
-
Object
- Object
- RightDevelop::Commands::Git
- Includes:
- RightSupport::Log::Mixin
- Defined in:
- lib/right_develop/commands/git.rb
Constant Summary collapse
- NAME_SPLIT_CHARS =
/-|_|\//
- YES =
/(ye?s?)/i
- NO =
/(no?)/i
- TASKS =
%w(prune tickets)
- MERGE_COMMENT =
/^Merge (?:remote[- ])?(?:tracking )?(?:branch|pull request #[0-9]+ from) ['"]?(.*)['"]?$/i
- WORD_BOUNDARY =
%r{[_ /-]+}
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.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/right_develop/commands/git.rb', line 108 def initialize(repo, task, ) logger = Logger.new(STDERR) logger.level = [:debug] ? Logger::DEBUG : Logger::WARN RightSupport::Log::Mixin.default_logger = logger # Post-process "age" option; transform from natural-language expression into a timestamp. if (age = .delete(:age)) 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 # Post-process "since" option; transform into a Regexp. if (link = .delete(:link)) link = Regexp.new("^#{link}") [:link] = link end @git = repo @task = task @options = end |
Class Method Details
.create ⇒ Object
Parse command-line options and create a Command object
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/right_develop/commands/git.rb', line 43 def self.create task_list = TASKS.map { |c| " * #{c}" }.join("\n") = Trollop. do <<-EOS The 'git' command automates various repository management tasks. All tasks accept the same options, although not every option applies to every command. Usage: right_develop git <task> [options] Where <task> is one of: #{task_list} And [options] are selected from: EOS 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|ve?r?)?[0-9.]+" opt :local, "Limit to local branches" opt :remote, "Limit to remote branches" opt :merged, "Limit to branches that are merged into this branch", :type => :string, :default => "master" opt :since, "Base branch or tag to compare against for determining 'new' commits", :default => "origin/master" opt :link, "Word prefix indicating a link to an external ticketing system", :default => "(?:[#A-Za-z]+)([0-9]+)$" opt :link_to, "URL pattern to generate ticket links, don't forget trailing slash!", :type => :string opt :debug, "Enable verbose debug output", :default => false end task = ARGV.shift repo = ::RightGit::Git::Repository.new( ::Dir.pwd, ::RightDevelop::Utility::Git::DEFAULT_REPO_OPTIONS) case task when "prune" self.new(repo, :prune, ) when "tickets" self.new(repo, :tickets, ) 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.
144 145 146 147 148 149 150 151 152 153 |
# File 'lib/right_develop/commands/git.rb', line 144 def run case @task when :prune prune(@options) when :tickets tickets(@options) else raise StateError, "Invalid @task; check Git.create!" end end |