Module: ChurnVsComplexity::CLI::Parser

Defined in:
lib/churn_vs_complexity/cli/parser.rb

Class Method Summary collapse

Class Method Details

.createObject



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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/churn_vs_complexity/cli/parser.rb', line 8

def self.create
  options = { excluded: [] }
  parser = OptionParser.new do |opts|
    opts.banner = 'Usage: churn_vs_complexity [options] folder'

    opts.on('--java', 'Check complexity of java classes') do
      options[:language] = :java
    end

    opts.on('--ruby', 'Check complexity of ruby files') do
      options[:language] = :ruby
    end

    opts.on('--js', '--ts', '--javascript', '--typescript',
            'Check complexity of javascript and typescript files',) do
      options[:language] = :javascript
    end

    opts.on('--csv', 'Format output as CSV') do
      options[:serializer] = :csv
    end

    opts.on('--graph', 'Format output as HTML page with Churn vs Complexity graph') do
      options[:serializer] = :graph
    end

    opts.on('--summary', 'Output summary statistics (mean and median) for churn and complexity') do
      options[:serializer] = :summary
    end

    opts.on('--excluded PATTERN',
            'Exclude file paths including this string. Can be used multiple times.',) do |value|
      options[:excluded] << value
    end

    opts.on('--since YYYY-MM-DD',
            'Normal mode: Calculate churn after this date. Timetravel mode: calculate summaries from this date',) do |value|
      options[:since] = value
    end

    opts.on('-m', '--month', 'Calculate churn for the month leading up to the most recent commit') do
      options[:relative_period] = :month
    end

    opts.on('-q', '--quarter', 'Calculate churn for the quarter leading up to the most recent commit') do
      options[:relative_period] = :quarter
    end

    opts.on('-y', '--year', 'Calculate churn for the year leading up to the most recent commit') do
      options[:relative_period] = :year
    end

    opts.on('--timetravel N',
            'Calculate summary for all commits at intervals of N days throughout project history or from the date specified with --since',) do |value|
      options[:mode] = :timetravel
      options[:jump_days] = value.to_i
    end

    opts.on('--delta SHA',
            'Identify changes between the specified commit (SHA) and the previous commit and annotate changed files with complexity score. SHA can be a full or short commit hash, or the value HEAD. Can be used multiple times to specify multiple commits.',) do |value|
      options[:mode] = :delta
      (options[:commits] ||= []) << value
    end

    opts.on('--dry-run', 'Echo the chosen options from the CLI') do
      puts options
      exit
    end

    opts.on('-h', '--help', 'Display help') do
      puts opts
      exit
    end

    opts.on('--version', 'Display version') do
      puts ChurnVsComplexity::VERSION
      exit
    end
  end
  [parser, options]
end