lib/polytrix/cli.rb in polytrix-0.1.2 vs lib/polytrix/cli.rb in polytrix-0.1.3

- old
+ new

@@ -1,9 +1,10 @@ require 'thor' require 'polytrix' require 'polytrix/command' +require 'polytrix/command/report' module Polytrix class CLI < Thor # rubocop:disable ClassLength # Common module to load and invoke a CLI-implementation agnostic command. module PerformCommand @@ -27,12 +28,10 @@ }.merge(additional_options) str_const = Thor::Util.camel_case(command) klass = ::Polytrix::Command.const_get(str_const) klass.new(args, options, command_options).call - rescue ArgumentError => e - abort e.message end end include Logging include PerformCommand @@ -42,76 +41,96 @@ MAX_CONCURRENCY = 9999 # Constructs a new instance. def initialize(*args) super + Polytrix.logger = Polytrix.default_file_logger $stdout.sync = true end + def self.filter_options + method_option :failed, + type: :boolean, + desc: 'Only list tests that failed / passed' + method_option :skipped, + type: :boolean, + desc: 'Only list tests that were skipped / executed' + method_option :samples, + type: :boolean, + desc: 'Only list tests that have sample code / do not have sample code' + end + desc 'list [INSTANCE|REGEXP|all]', 'Lists one or more scenarios' - method_option :bare, - aliases: '-b', - type: :boolean, - desc: 'List the name of each scenario only, one per line' method_option :log_level, aliases: '-l', desc: 'Set the log level (debug, info, warn, error, fatal)' + method_option :format, + desc: 'List output format', + enum: %w(text markdown json yaml), + default: 'text' method_option :manifest, aliases: '-m', desc: 'The Polytrix test manifest file location', default: 'polytrix.yml' method_option :test_dir, aliases: '-t', desc: 'The Polytrix test directory', default: 'tests/polytrix' method_option :solo, desc: 'Enable solo mode - Polytrix will auto-configure a single implementor and its scenarios' - # , default: 'polytrix.yml' + # , default: 'polytrix.yml' method_option :solo_glob, desc: 'The globbing pattern to find code samples in solo mode' + method_option :source, + type: :boolean, + desc: 'Include source file in listing' + filter_options def list(*args) update_config! perform('list', 'list', args, options) end - desc 'report [INSTANCE|REGEXP|all]', 'Summary report for one or more scenarios' - method_option :bare, - aliases: '-b', - type: :boolean, - desc: 'List the name of each scenario only, one per line' + desc 'show [INSTANCE|REGEXP|all]', 'Show detailed status for one or more scenarios' method_option :log_level, aliases: '-l', desc: 'Set the log level (debug, info, warn, error, fatal)' + method_option :format, + desc: 'List output format', + enum: %w(text markdown json yaml), + default: 'text' method_option :manifest, aliases: '-m', desc: 'The Polytrix test manifest file location', default: 'polytrix.yml' method_option :test_dir, aliases: '-t', desc: 'The Polytrix test directory', default: 'tests/polytrix' method_option :solo, desc: 'Enable solo mode - Polytrix will auto-configure a single implementor and its scenarios' - # , default: 'polytrix.yml' + # , default: 'polytrix.yml' method_option :solo_glob, desc: 'The globbing pattern to find code samples in solo mode' - def report(*args) + filter_options + def show(*args) update_config! - perform('report', 'report', args, options) + perform('show', 'show', args, options) end { - clone: "Change scenario state to cloned. " \ - "Clone the code sample from git", - bootstrap: "Change scenario state to bootstraped. " \ - "Running bootstrap scripts for the implementor", - exec: "Change instance state to executed. " \ - "Execute the code sample and capture the results.", - verify: "Change instance state to verified. " \ - "Assert that the captured results match the expectations for the scenario.", - destroy: "Change scenario state to destroyed. " \ - "Delete all information for one or more scenarios" + clone: 'Change scenario state to cloned. ' \ + 'Clone the code sample from git', + bootstrap: 'Change scenario state to bootstraped. ' \ + 'Running bootstrap scripts for the implementor', + detect: 'Find sample code that matches a test scenario. ' \ + 'Attempts to locate a code sample with a filename that the test scenario name.', + exec: 'Change instance state to executed. ' \ + 'Execute the code sample and capture the results.', + verify: 'Change instance state to verified. ' \ + 'Assert that the captured results match the expectations for the scenario.', + destroy: 'Change scenario state to destroyed. ' \ + 'Delete all information for one or more scenarios' }.each do |action, short_desc| desc( "#{action} [INSTANCE|REGEXP|all]", short_desc ) @@ -144,11 +163,10 @@ method_option :solo_glob, desc: 'The globbing pattern to find code samples in solo mode' define_method(action) do |*args| update_config! action_options = options.dup - action_options['on'] = :implementor if [:clone, :bootstrap].include? action perform(action, 'action', args, action_options) end end desc 'test [INSTANCE|REGEXP|all]', @@ -177,66 +195,32 @@ aliases: '-t', desc: 'The Polytrix test directory', default: 'tests/polytrix' method_option :solo, desc: 'Enable solo mode - Polytrix will auto-configure a single implementor and its scenarios' - # , default: 'polytrix.yml' + # , default: 'polytrix.yml' method_option :solo_glob, desc: 'The globbing pattern to find code samples in solo mode' def test(*args) update_config! action_options = options.dup perform('test', 'test', args, action_options) end - desc 'code2doc [INSTANCE|REGEXP|all]', - 'Generates documenation from sample code for one or more scenarios' - long_desc <<-DESC - This task will convert annotated sample code to documentation. Markdown or - reStructureText are supported. - DESC - method_option :log_level, - aliases: '-l', - desc: 'Set the log level (debug, info, warn, error, fatal)' - method_option :manifest, - aliases: '-m', - desc: 'The Polytrix test manifest file location', - default: 'polytrix.yml' - method_option :solo, - desc: 'Enable solo mode - Polytrix will auto-configure a single implementor and its scenarios' - # , default: 'polytrix.yml' - method_option :solo_glob, - desc: 'The globbing pattern to find code samples in solo mode' - method_option :format, - aliases: '-f', - enum: %w(md rst), - default: 'md', - desc: 'Target documentation format' - method_option :target_dir, - aliases: '-d', - default: 'docs/', - desc: 'The target directory where documentation for generated documentation.' - def code2doc(*args) - update_config! - action_options = options.dup - perform('code2doc', 'action', args, action_options) - end - desc 'version', "Print Polytrix's version information" def version puts "Polytrix version #{Polytrix::VERSION}" end - map %w[-v --version] => :version + map %w(-v --version) => :version - # register Polytrix::CLI::Report, "init", - # "init", "Adds some configuration to your cookbook so Polytrix can rock" - # long_desc <<-D, :for => "init" - # Init will add Test Polytrix support to an existing project for - # convergence integration testing. A default .polytrix.yml file (which is - # intended to be customized) is created in the project's root directory - # and one or more gems will be added to the project's Gemfile. + desc 'report', 'Generate reports' + subcommand 'report', Polytrix::Command::Report + # register Polytrix::Command::Report, 'report', + # 'report', 'Generates a report' + # long_desc <<-D, for: 'report' + # Polytrix will generate an HTML report. # D - # tasks["init"].options = Polytrix::CLI::Report.class_options + # tasks['report'].options = Polytrix::Command::Report.class_options private # Ensure the any failing commands exit non-zero. #