Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

feature: Provide --all option for working with single files.

Merge branch 'FND-shortcut'
  • Loading branch information...
commit d610ea3b7e35554b37001f697cc05e691687b1f0 2 parents dab8c58 + 1afc85c
Xavier Shay xaviershay authored

Showing 3 changed files with 25 additions and 0 deletions. Show diff stats Hide diff stats

  1. +1 0  README.md
  2. +12 0 lib/cane/cli/parser.rb
  3. +12 0 spec/parser_spec.rb
1  README.md
Source Rendered
@@ -52,6 +52,7 @@ Customize behaviour with a wealth of options:
52 52
53 53 --gte FILE,THRESHOLD If FILE contains a number, verify it is >= to THRESHOLD
54 54
  55 + -f, --all FILE Apply all checks to given file
55 56 --max-violations VALUE Max allowed violations (default: 0)
56 57 --parallel Use all processors. Slower on small projects, faster on large.
57 58
12 lib/cane/cli/parser.rb
@@ -28,6 +28,7 @@ def initialize(stdout = $stdout)
28 28 Cane.default_checks.each do |check|
29 29 add_check_options(check)
30 30 end
  31 + add_checks_shortcut
31 32
32 33 add_cane_options
33 34
@@ -116,6 +117,17 @@ def add_cane_options
116 117 parser.separator ""
117 118 end
118 119
  120 + def add_checks_shortcut
  121 + description = "Apply all checks to given file"
  122 + parser.on("-f", "--all FILE", description) do |f|
  123 + # This is a bit of a hack, but provides a really useful UI for
  124 + # dealing with single files. Let's see how it evolves.
  125 + options[:abc_glob] = f
  126 + options[:style_glob] = f
  127 + options[:doc_glob] = f
  128 + end
  129 + end
  130 +
119 131 def add_version
120 132 parser.on_tail("-v", "--version", "Show version") do
121 133 stdout.puts Cane::VERSION
12 spec/parser_spec.rb
@@ -27,6 +27,18 @@ def run(cli_args)
27 27 result[:max_violations].should == 1
28 28 end
29 29
  30 + it 'uses positional arguments as shortcut for individual files' do
  31 + output, result = run("--all mysinglefile")
  32 + result[:abc_glob].should == 'mysinglefile'
  33 + result[:style_glob].should == 'mysinglefile'
  34 + result[:doc_glob].should == 'mysinglefile'
  35 +
  36 + output, result = run("--all mysinglefile --abc-glob myotherfile")
  37 + result[:abc_glob].should == 'myotherfile'
  38 + result[:style_glob].should == 'mysinglefile'
  39 + result[:doc_glob].should == 'mysinglefile'
  40 + end
  41 +
30 42 it 'displays a help message' do
31 43 output, result = run("--help")
32 44

0 comments on commit d610ea3

Please sign in to comment.
Something went wrong with that request. Please try again.