Class: GitCurate::CLIParser

Inherits:
Object
  • Object
show all
Defined in:
lib/git_curate/cli_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLIParser



9
10
11
# File 'lib/git_curate/cli_parser.rb', line 9

def initialize
  @parsed_options = {}
end

Instance Attribute Details

#parsed_optionsObject (readonly)

Returns the value of attribute parsed_options.



7
8
9
# File 'lib/git_curate/cli_parser.rb', line 7

def parsed_options
  @parsed_options
end

Instance Method Details

#parse(options) ⇒ Object

Sets @parsed_options according to the options received, and return truthy if and only if the program should continue after the options are passed. Usually this method should be passed ARGV. Any elements of ‘options` that are not processed by this method, will remain in `options`; elements that are processed, will be destructively removed from `options`.



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
# File 'lib/git_curate/cli_parser.rb', line 17

def parse(options)
  opt_parser = OptionParser.new do |opts|
    opts.banner = "  Usage: git curate [options]\n\n  Interactively step through the local branches of the current git repository, showing various\n  information and asking whether to keep or delete each branch.\n\n  In the default (interactive) mode, the current branch is excluded, as it cannot be deleted.\n\n  Note git-curate does not perform a \"git fetch\"; if you want to be sure the output reflects the current\n  state of any remotes, run \"git fetch\" first.\n\n  Options:\n  EOF\n\n    opts.on(\n      \"-l\",\n      \"--list\",\n      \"Show summary of local branches, including current branch, without stepping through interactively\"\n    ) do\n      self.parsed_options[:list] = true\n    end\n\n    opts.on(\n      \"--merged\",\n      \"Only list branches whose tips are reachable from HEAD\",\n    ) do\n      self.parsed_options[:merged_opt] = \"--merged\"\n    end\n\n    opts.on(\n      \"--no-merged\",\n      \"Only list branches whose tips are not reachable from HEAD\",\n    ) do\n      self.parsed_options[:merged_opt] = \"--no-merged\"\n    end\n\n    opts.on(\"-h\", \"Print this help message\") do\n      puts opts\n      return false\n    end\n\n    opts.on(\"-v\", \"--version\", \"Print the currently installed version of this program\") do\n      puts \"git curate v\#{GitCurate::VERSION} \#{GitCurate::COPYRIGHT}\"\n      return false\n    end\n  end\n\n  opt_parser.parse!(options)\n  return true\nend\n"