Class: RubyCritic::Cli::Options
- Inherits:
-
Object
- Object
- RubyCritic::Cli::Options
- Defined in:
- lib/rubycritic/cli/options.rb
Instance Method Summary collapse
-
#initialize(argv) ⇒ Options
constructor
A new instance of Options.
-
#parse ⇒ Object
rubocop:disable Metrics/MethodLength.
- #to_h ⇒ Object
Constructor Details
#initialize(argv) ⇒ Options
Returns a new instance of Options.
9 10 11 12 |
# File 'lib/rubycritic/cli/options.rb', line 9 def initialize(argv) @argv = argv self.parser = OptionParser.new end |
Instance Method Details
#parse ⇒ Object
rubocop:disable Metrics/MethodLength
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 71 72 73 74 75 76 77 78 |
# File 'lib/rubycritic/cli/options.rb', line 15 def parse parser.new do |opts| opts. = 'Usage: rubycritic [options] [paths]' opts.on('-p', '--path [PATH]', 'Set path where report will be saved (tmp/rubycritic by default)') do |path| @root = path end opts.on('-b', '--branch BRANCH', 'Set branch to compare') do |branch| self.base_branch = String(branch) set_current_branch self.mode = :compare_branches end opts.on('-t', '--maximum-decrease [MAX_DECREASE]', 'Set a threshold for score difference between two branches (works only with -b)') do |threshold_score| self.threshold_score = Integer(threshold_score) end opts.on( '-f', '--format [FORMAT]', %i[html json console lint], 'Report smells in the given format:', ' html (default; will open in a browser)', ' json', ' console', ' lint' ) do |format| self.format = format end opts.on('-s', '--minimum-score [MIN_SCORE]', 'Set a minimum score') do |min_score| self.minimum_score = Float(min_score) end opts.on('-m', '--mode-ci [BASE_BRANCH]', 'Use CI mode (faster, analyses diffs w.r.t base_branch (default: master))') do |branch| self.base_branch = branch || 'master' set_current_branch self.mode = :ci end opts.on('--deduplicate-symlinks', 'De-duplicate symlinks based on their final target') do self.deduplicate_symlinks = true end opts.on('--suppress-ratings', 'Suppress letter ratings') do self. = true end opts.on('--no-browser', 'Do not open html report with browser') do self.no_browser = true end opts.on_tail('-v', '--version', "Show gem's version") do self.mode = :version end opts.on_tail('-h', '--help', 'Show this message') do self.mode = :help end end.parse!(@argv) self end |
#to_h ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rubycritic/cli/options.rb', line 80 def to_h { mode: mode, root: root, format: format, deduplicate_symlinks: deduplicate_symlinks, paths: paths, suppress_ratings: , help_text: parser.help, minimum_score: minimum_score || 0, no_browser: no_browser, base_branch: base_branch, feature_branch: feature_branch, threshold_score: threshold_score || 0 } end |