This repository has been archived by the owner on Sep 19, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrew Crump
committed
Jan 22, 2012
1 parent
5c9114b
commit 7802018
Showing
6 changed files
with
86 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
#!/usr/bin/env ruby | ||
require_relative '../lib/foodcritic' | ||
result, status = FoodCritic::Linter.check(ARGV) | ||
puts result; exit status.to_i | ||
module FoodCritic | ||
cmd_line = CommandLine.new(ARGV) | ||
review, status = Linter.check(cmd_line) | ||
SummaryOutput.new.output(review) | ||
exit status.to_i | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
require 'chef' | ||
require 'pry' | ||
require_relative 'foodcritic/command_line' | ||
require_relative 'foodcritic/domain' | ||
require_relative 'foodcritic/error_checker' | ||
require_relative 'foodcritic/helpers' | ||
require_relative 'foodcritic/dsl' | ||
require_relative 'foodcritic/linter' | ||
require_relative 'foodcritic/output' | ||
require_relative 'foodcritic/version' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module FoodCritic | ||
|
||
# Command line parsing. | ||
class CommandLine | ||
|
||
# Create a new instance of CommandLine | ||
# | ||
# @param [Array] args The command line arguments | ||
def initialize(args) | ||
@args = args | ||
@options = {} | ||
@options[:fail_tags] = []; @options[:tags] = [] | ||
@parser = OptionParser.new do |opts| | ||
opts.banner = 'foodcritic [cookbook_path]' | ||
opts.on("-r", "--[no-]repl", "Drop into a REPL for interactive rule editing.") {|r|options[:repl] = r} | ||
opts.on("-t", "--tags TAGS", "Only check against rules with the specified tags.") {|t|options[:tags] << t} | ||
opts.on("-f", "--epic-fail TAGS", "Fail the build if any of the specified tags are matched.") {|t|options[:fail_tags] << t} | ||
end | ||
@parser.parse!(args) unless show_help? | ||
end | ||
|
||
# Show the command help to the end user? | ||
# | ||
# @return [Boolean] True if help should be shown. | ||
def show_help? | ||
@args.length == 1 and @args.first == '--help' | ||
end | ||
|
||
# The help text. | ||
# | ||
# @return [String] Help text describing the command-line options available. | ||
def help | ||
@parser.help | ||
end | ||
|
||
# If the cookbook path provided is valid | ||
# | ||
# @return [Boolean] True if the path is a directory that exists. | ||
def valid_path? | ||
@args.length == 1 and Dir.exists?(@args[0]) | ||
end | ||
|
||
# The cookbook path | ||
# | ||
# @return [String] Path to the cookbook(s) being checked. | ||
def cookbook_path | ||
@args[0] | ||
end | ||
|
||
# Parsed command-line options | ||
# | ||
# @return [Hash] The parsed command-line options. | ||
def options | ||
@options | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module FoodCritic | ||
|
||
# Default output showing a summary view. | ||
class SummaryOutput | ||
# Output a summary view only listing the matching rules, file and line number. | ||
# | ||
# @param [Review] review The review to output. | ||
def output(review) | ||
puts review.to_s | ||
end | ||
end | ||
|
||
end |