codeclimate 0.45.0 → 0.46.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d44dd1c05b63256236f2262283aa00f4c1c629ac
4
- data.tar.gz: 7cff0c14c73e7cb501c2038ba8d9e998d8ce42bf
3
+ metadata.gz: a022d2dd262f4b69810a0039df68c2c35cbce1b1
4
+ data.tar.gz: c91433584f2f30204f7e91ff73eee620acf238de
5
5
  SHA512:
6
- metadata.gz: 8381828b97b80d0400010a2d57c4093bd270a883a01ef66e8c8d7dbb75cfac91170ea1e356d535e7d20e9a294513f010a227a791a690e5231c0228e9b1c96a80
7
- data.tar.gz: 38ca8a4dbc3eff1f78c14f1f5d1ffe87b42a5550afee622478aa68594cc561d0622b9e6314730bf3e4ed0c5e2f9865c1a19e92b857878adce621754b80d0629d
6
+ metadata.gz: 8647501044a5a159e06b1c3b708a0fbb33c6c1aa6b18a6743923ebb5516406e229042b252a52f611239c34bad8c4bbf5a77c6d3b3e3ad2c17d5c967fa8279184
7
+ data.tar.gz: 4a60df0d24f319050ddef3610bd12071cd318db1508f34e2593c09ba9ab9ac3d5d73aabacd909b8ebe6297729581e5f21c0bc54c93308b7ca51a634536b66024
@@ -5,20 +5,20 @@ require "cc/analyzer"
5
5
  require "cc/workspace"
6
6
  require "cc/yaml"
7
7
 
8
+ require "cc/cli/analyze"
9
+ require "cc/cli/command"
10
+ require "cc/cli/console"
11
+ require "cc/cli/engines"
12
+ require "cc/cli/help"
13
+ require "cc/cli/init"
14
+ require "cc/cli/prepare"
15
+ require "cc/cli/runner"
16
+ require "cc/cli/test"
17
+ require "cc/cli/validate_config"
18
+ require "cc/cli/version"
19
+
8
20
  module CC
9
21
  module CLI
10
- autoload :Analyze, "cc/cli/analyze"
11
- autoload :Command, "cc/cli/command"
12
- autoload :Console, "cc/cli/console"
13
- autoload :Engines, "cc/cli/engines"
14
- autoload :Help, "cc/cli/help"
15
- autoload :Init, "cc/cli/init"
16
- autoload :Prepare, "cc/cli/prepare"
17
- autoload :Runner, "cc/cli/runner"
18
- autoload :Test, "cc/cli/test"
19
- autoload :ValidateConfig, "cc/cli/validate_config"
20
- autoload :Version, "cc/cli/version"
21
-
22
22
  def self.debug?
23
23
  ENV["CODECLIMATE_DEBUG"]
24
24
  end
@@ -1,6 +1,17 @@
1
+ require "cc/cli/command"
2
+
1
3
  module CC
2
4
  module CLI
3
5
  class Analyze < Command
6
+ ARGUMENT_LIST = "[-f format] [-e engine[:channel]] [path]".freeze
7
+ SHORT_HELP = "Run analysis with the given arguments".freeze
8
+ HELP = "#{SHORT_HELP}\n" \
9
+ "\n" \
10
+ " -f <format>, --format <format> Format of output. Possible values: #{CC::Analyzer::Formatters::FORMATTERS.keys.join ", "}\n" \
11
+ " -e <engine[:channel]> Engine to run. Can be specified multiple times.\n" \
12
+ " --dev Run in development mode. Engines installed locally that are not in the manifest will be run.\n" \
13
+ " path Path to check. Can be specified multiple times.".freeze
14
+
4
15
  include CC::Analyzer
5
16
 
6
17
  def initialize(_args = [])
@@ -7,6 +7,50 @@ module CC
7
7
  module CLI
8
8
  class Command
9
9
  CODECLIMATE_YAML = ".codeclimate.yml".freeze
10
+ NAMESPACE = name.split("::")[0..-2].join("::").freeze
11
+
12
+ def self.abstract!
13
+ @abstract = true
14
+ end
15
+
16
+ def self.abstract?
17
+ @abstract == true
18
+ end
19
+
20
+ def self.all
21
+ @@subclasses.reject(&:abstract?)
22
+ end
23
+
24
+ def self.[](name)
25
+ all.find { |command| command.name == "#{NAMESPACE}::#{name}" || command.command_name == name }
26
+ end
27
+
28
+ # rubocop: disable Style/ClassVars
29
+ def self.inherited(subclass)
30
+ @@subclasses ||= []
31
+ @@subclasses << subclass
32
+ end
33
+ # rubocop: enable Style/ClassVars
34
+
35
+ def self.synopsis
36
+ "#{command_name} #{self::ARGUMENT_LIST if const_defined?(:ARGUMENT_LIST)}".strip
37
+ end
38
+
39
+ def self.short_help
40
+ if const_defined? :SHORT_HELP
41
+ self::SHORT_HELP
42
+ else
43
+ ""
44
+ end
45
+ end
46
+
47
+ def self.help
48
+ if const_defined? :HELP
49
+ self::HELP
50
+ else
51
+ short_help
52
+ end
53
+ end
10
54
 
11
55
  def initialize(args = [])
12
56
  @args = args
@@ -17,7 +61,9 @@ module CC
17
61
  end
18
62
 
19
63
  def self.command_name
20
- name[/[^:]*$/].split(/(?=[A-Z])/).map(&:downcase).join("-")
64
+ name.gsub(/^#{NAMESPACE}::/, "").split("::").map do |part|
65
+ part.split(/(?=[A-Z])/).map(&:downcase).join("-")
66
+ end.join(":")
21
67
  end
22
68
 
23
69
  def execute
@@ -1,6 +1,8 @@
1
1
  module CC
2
2
  module CLI
3
3
  class Console < Command
4
+ SHORT_HELP = "Open a ruby console for the CLI. Useful for developing against the CLI.".freeze
5
+
4
6
  def run
5
7
  require "pry"
6
8
  binding.pry(quiet: true, prompt: Pry::SIMPLE_PROMPT, output: $stdout)
@@ -1,14 +1,8 @@
1
1
  require "cc/analyzer"
2
2
 
3
- module CC
4
- module CLI
5
- module Engines
6
- autoload :Disable, "cc/cli/engines/disable"
7
- autoload :Enable, "cc/cli/engines/enable"
8
- autoload :EngineCommand, "cc/cli/engines/engine_command"
9
- autoload :Install, "cc/cli/engines/install"
10
- autoload :List, "cc/cli/engines/list"
11
- autoload :Remove, "cc/cli/engines/remove"
12
- end
13
- end
14
- end
3
+ require "cc/cli/engines/disable"
4
+ require "cc/cli/engines/enable"
5
+ require "cc/cli/engines/engine_command"
6
+ require "cc/cli/engines/install"
7
+ require "cc/cli/engines/list"
8
+ require "cc/cli/engines/remove"
@@ -1,9 +1,16 @@
1
1
  require "cc/analyzer"
2
+ require "cc/cli/engines/engine_command"
2
3
 
3
4
  module CC
4
5
  module CLI
5
6
  module Engines
6
7
  class Disable < EngineCommand
8
+ ARGUMENT_LIST = "<engine_name>".freeze
9
+ SHORT_HELP = "Disable an engine in your codeclimate.yml.".freeze
10
+ HELP = "#{SHORT_HELP}\n" \
11
+ "\n"\
12
+ " <engine_name> Engine to disable in your codeclimate.yml".freeze
13
+
7
14
  def run
8
15
  require_codeclimate_yml
9
16
 
@@ -4,6 +4,12 @@ module CC
4
4
  module CLI
5
5
  module Engines
6
6
  class Enable < EngineCommand
7
+ ARGUMENT_LIST = "<engine_name>".freeze
8
+ SHORT_HELP = "Enable an engine in your codeclimate.yml.".freeze
9
+ HELP = "#{SHORT_HELP}\n" \
10
+ "\n"\
11
+ " <engine_name> Engine to enable in your codeclimate.yml".freeze
12
+
7
13
  def run
8
14
  require_codeclimate_yml
9
15
 
@@ -6,6 +6,8 @@ module CC
6
6
  class EngineCommand < Command
7
7
  include CC::Analyzer
8
8
 
9
+ abstract!
10
+
9
11
  private
10
12
 
11
13
  def engine_name
@@ -2,6 +2,8 @@ module CC
2
2
  module CLI
3
3
  module Engines
4
4
  class Install < EngineCommand
5
+ SHORT_HELP = "Pull the latest images for enabled engines in your codeclimate.yml.".freeze
6
+
5
7
  ImagePullFailure = Class.new(StandardError)
6
8
 
7
9
  def run
@@ -2,6 +2,8 @@ module CC
2
2
  module CLI
3
3
  module Engines
4
4
  class List < EngineCommand
5
+ SHORT_HELP = "List all available engines".freeze
6
+
5
7
  def run
6
8
  say "Available engines:"
7
9
  engine_registry_list.sort_by { |name, _| name }.each do |name, attributes|
@@ -4,6 +4,12 @@ module CC
4
4
  module CLI
5
5
  module Engines
6
6
  class Remove < EngineCommand
7
+ ARGUMENT_LIST = "<engine_name>".freeze
8
+ SHORT_HELP = "Remove an engine from your codeclimate.yml.".freeze
9
+ HELP = "#{SHORT_HELP} This command deletes the config rather than setting it to disabled.\n" \
10
+ "\n"\
11
+ " <engine_name> Engine to remove from your codeclimate.yml".freeze
12
+
7
13
  def run
8
14
  require_codeclimate_yml
9
15
 
@@ -3,34 +3,45 @@ require "rainbow"
3
3
  module CC
4
4
  module CLI
5
5
  class Help < Command
6
+ ARGUMENT_LIST = "[command]".freeze
7
+ SHORT_HELP = "Display help information.".freeze
8
+ HELP = "#{SHORT_HELP}\n" \
9
+ "\n" \
10
+ " no arguments Show help summary for all commands.\n" \
11
+ " [command] Show help for specific commands. Can be specified multiple times.".freeze
12
+
6
13
  def run
7
- say "Usage: codeclimate COMMAND ...\n\nAvailable commands:\n"
8
- commands.each do |command|
9
- say " #{command}"
14
+ if @args.any?
15
+ @args.each do |command|
16
+ show_help(command)
17
+ end
18
+ else
19
+ show_help_summary
10
20
  end
11
21
  end
12
22
 
13
23
  private
14
24
 
15
- def commands
16
- [
17
- "analyze [-f format] [-e engine(:channel)] [path]",
18
- "console",
19
- "engines:disable #{underline("engine_name")}",
20
- "engines:enable #{underline("engine_name")}",
21
- "engines:install",
22
- "engines:list",
23
- "engines:remove #{underline("engine_name")}",
24
- "prepare",
25
- "help",
26
- "init",
27
- "validate-config",
28
- "version",
29
- ].freeze
25
+ def show_help(command_name)
26
+ command = Command[command_name]
27
+ say "Usage: codeclimate #{command.synopsis}\n"
28
+ say "\n"
29
+ say "#{command.help}\n"
30
+ say "\n\n"
30
31
  end
31
32
 
32
- def underline(string)
33
- Rainbow.new.wrap(string).underline
33
+ def show_help_summary
34
+ short_helps =
35
+ Command.all.sort_by(&:command_name).map do |command|
36
+ [command.synopsis, command.short_help]
37
+ end.compact.to_h
38
+
39
+ longest_command_length = short_helps.keys.map(&:length).max
40
+
41
+ say "Usage: codeclimate COMMAND ...\n\nAvailable commands:\n"
42
+ short_helps.each do |command, help|
43
+ say format(" %-#{longest_command_length}s %s\n", command, help)
44
+ end
34
45
  end
35
46
  end
36
47
  end
@@ -7,6 +7,12 @@ module CC
7
7
  class Init < Command
8
8
  include CC::Analyzer
9
9
 
10
+ ARGUMENT_LIST = "[--upgrade]".freeze
11
+ SHORT_HELP = "Generate a configuration based on the contents of your repo.".freeze
12
+ HELP = "#{SHORT_HELP}\n" \
13
+ "\n" \
14
+ " --upgrade Upgrade a Code Climate Classic configuration".freeze
15
+
10
16
  def run
11
17
  if !upgrade? && filesystem.exist?(CODECLIMATE_YAML)
12
18
  warn "Config file .codeclimate.yml already present.\nTry running 'validate-config' to check configuration."
@@ -10,6 +10,12 @@ require "uri"
10
10
  module CC
11
11
  module CLI
12
12
  class Prepare < Command
13
+ ARGUMENT_LIST = "[--allow-internal-ips]".freeze
14
+ SHORT_HELP = "Run the commands in your prepare step.".freeze
15
+ HELP = "#{SHORT_HELP}\n" \
16
+ "\n" \
17
+ " --allow-internal-ips Allow fetching from internal IPs.".freeze
18
+
13
19
  InternalHostError = Class.new(StandardError)
14
20
  FetchError = Class.new(StandardError)
15
21
 
@@ -31,25 +31,30 @@ module CC
31
31
  end
32
32
 
33
33
  def command_class
34
- CLI.const_get(command_name)
34
+ command_const = Command[command]
35
+ if command_const.abstract?
36
+ nil
37
+ else
38
+ command_const
39
+ end
35
40
  rescue NameError
36
41
  nil
37
42
  end
38
43
 
39
- def command_name
40
- case command
41
- when nil, "-h", "-?", "--help" then "Help"
42
- when "-v", "--version" then "Version"
43
- else command.sub(":", "::").underscore.camelize
44
- end
45
- end
46
-
47
44
  def command_arguments
48
45
  @args[1..-1]
49
46
  end
50
47
 
51
48
  def command
52
- @args.first
49
+ command_name = @args.first
50
+ case command_name
51
+ when nil, "-h", "-?", "--help"
52
+ "help"
53
+ when "-v", "--version"
54
+ "version"
55
+ else
56
+ command_name
57
+ end
53
58
  end
54
59
  end
55
60
  end
@@ -1,4 +1,5 @@
1
1
  require "cc/yaml"
2
+ require "tmpdir"
2
3
 
3
4
  module CC
4
5
  module CLI
@@ -68,6 +69,12 @@ module CC
68
69
  end
69
70
 
70
71
  class Test < Command
72
+ ARGUMENT_LIST = "<engine_name>".freeze
73
+ SHORT_HELP = "Test an engine.".freeze
74
+ HELP = "Validate that an engine is behaving correctly.\n" \
75
+ "\n"\
76
+ " <engine_name> Engine to test".freeze
77
+
71
78
  def run
72
79
  @engine_name = @args.first
73
80
 
@@ -3,6 +3,8 @@ require "cc/yaml"
3
3
  module CC
4
4
  module CLI
5
5
  class ValidateConfig < Command
6
+ SHORT_HELP = "Validate your .codeclimate.yml.".freeze
7
+
6
8
  include CC::Analyzer
7
9
  include CC::Yaml
8
10
 
@@ -1,6 +1,8 @@
1
1
  module CC
2
2
  module CLI
3
3
  class Version < Command
4
+ SHORT_HELP = "Display the CLI version.".freeze
5
+
4
6
  def run
5
7
  say version
6
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codeclimate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.45.0
4
+ version: 0.46.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code Climate
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-27 00:00:00.000000000 Z
11
+ date: 2017-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -253,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
253
253
  version: '0'
254
254
  requirements: []
255
255
  rubyforge_project:
256
- rubygems_version: 2.5.2
256
+ rubygems_version: 2.4.5
257
257
  signing_key:
258
258
  specification_version: 4
259
259
  summary: Code Climate CLI