Class: ReleaseHx::CLI
- Inherits:
-
Thor
- Object
- Thor
- ReleaseHx::CLI
- Defined in:
- lib/releasehx/cli.rb
Class Method Summary collapse
- .exit_on_failure? ⇒ Boolean
-
.start(original_args = ARGV, config = {}) ⇒ Object
OVERRIDE .start to handle no-arguments and default subcommand behavior =======================================.
Instance Method Summary collapse
-
#default(source_arg) ⇒ Object
FIXME: This method is overly complex and handles too many concerns.
Class Method Details
.exit_on_failure? ⇒ Boolean
10 11 12 |
# File 'lib/releasehx/cli.rb', line 10 def self.exit_on_failure? true end |
.start(original_args = ARGV, config = {}) ⇒ Object
OVERRIDE .start to handle no-arguments and default subcommand behavior
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/releasehx/cli.rb', line 18 def self.start original_args = ARGV, config = {} # If user gave no arguments at all, or only gave --help, allow that through if original_args.empty? || (original_args.length == 1 && original_args.first =~ /^--?h(elp)?$/) show_usage_snippet return elsif original_args.length == 1 && original_args.first =~ /^--man(page)?$/ show_manpage return elsif original_args.length == 1 && original_args.first =~ /^--version$/ puts ReleaseHx::VERSION return else first = original_args[0] original_args.unshift 'default' unless first.start_with?('-') || all_tasks.key?(first) end super end |
Instance Method Details
#default(source_arg) ⇒ Object
FIXME: This method is overly complex and handles too many concerns. It should be broken down into smaller methods, each handling a specific CLI action or workflow. A major refactor is planned for post-0.1.0.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/releasehx/cli.rb', line 86 def default source_arg setup_logger ReleaseHx.logger.debug "Starting ReleaseHx with version/source: #{source_arg}" load_and_configure_settings(ReleaseHx.attrs['app_default_config_path']) if [:debug] begin config_dump = SgymlHelpers.deep_stringify_safe(@settings).to_yaml ReleaseHx.logger.debug "Operative config settings:\n#{config_dump}" rescue StandardError => e require 'pp' # pretty print ReleaseHx.logger.debug "Rescued config PP dump:\n#{PP.pp(@settings, +'')}" raise e end end source_arg_type = version_or_file(source_arg) if source_arg_type == :invalid raise Thor::Error, <<~ERRTXT ERROR: Invalid file extension for source file: #{source_arg} Valid draft file types are: #{ReleaseHx.attrs['draft_source_file_types']} Valid extensions are: #{ReleaseHx.attrs['draft_source_extensions']} ERRTXT end ReleaseHx.logger.info "Source type: #{source_arg_type}" if [:verbose] && @settings['origin'] ReleaseHx.logger.debug "✓ Source configured: #{@settings['origin']['source']}" end if [:check] if source_arg_type == :file raise Thor::Error, 'ERROR: Scan operations require a version number as the first argument.' end perform_scan(source_arg) return end if [:api_data] && ([:api_data].nil? || [:api_data].empty?) raise Thor::Error, 'Must specify a PATH for --api-data. E.g. --api-data cached-1-1-1.json' end if [:api_data] && !File.exist?([:api_data]) raise Thor::Error, "API data file not found: #{[:api_data]}" end if [:api_data] ReleaseHx.logger.debug "✓ Using cached API data: #{[:api_data]}" elsif [:fetch] ReleaseHx.logger.info "✓ Will fetch fresh data from #{@settings['origin']['source']} API" if [:verbose] end if [:api_data] && [:fetch] ReleaseHx.logger.warn 'Warning: --fetch ignored when --api-data is specified' end if [[:adoc], [:md], [:yaml]].compact.size > 1 raise Thor::Error, 'ERROR: Only one of --adoc, --md, or --yaml (or aliases) may be specified.' end if [:append] perform_append(source_arg) return end determine_operations(source_arg) end |