Class: Html2rss::CLI
- Inherits:
-
Thor
- Object
- Thor
- Html2rss::CLI
- Defined in:
- lib/html2rss/cli.rb
Overview
The Html2rss command line interface.
Constant Summary collapse
- AUTO_FALLBACK_CHAIN =
Ordered fallback chain attempted by auto strategy.
Html2rss::FeedPipeline::AutoFallback::CHAIN.freeze
- STRATEGY_OPTION_ENUM =
Supported CLI strategy option values.
(['auto'] + Html2rss::RequestService.strategy_names).uniq.freeze
- STRATEGY_OPTION_DESC =
User-facing strategy help text that reflects the current fallback chain.
[ 'Optional request strategy (defaults to auto; auto tries', "#{AUTO_FALLBACK_CHAIN.join(' -> ')})" ].join(' ').freeze
Class Method Summary collapse
-
.exit_on_failure? ⇒ Boolean
Whether Thor should terminate process on command failures.
Instance Method Summary collapse
- #auto(url) ⇒ void
- #feed(yaml_file, feed_name = nil) ⇒ void
-
#schema ⇒ void
Prints or writes the exported configuration JSON Schema.
-
#validate(yaml_file, feed_name = nil) ⇒ void
Validates a YAML config and prints the result.
Class Method Details
.exit_on_failure? ⇒ Boolean
Returns whether Thor should terminate process on command failures.
31 32 33 |
# File 'lib/html2rss/cli.rb', line 31 def self.exit_on_failure? true end |
Instance Method Details
#auto(url) ⇒ void
This method returns an undefined value.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/html2rss/cli.rb', line 81 def auto(url) # rubocop:disable Metrics/MethodLength format = .fetch(:format, 'rss') source_method = format == 'jsonfeed' ? Html2rss.method(:auto_json_feed) : Html2rss.method(:auto_source) result = execute_feed do source_method.call( url, strategy: current_strategy, items_selector: [:items_selector], max_redirects: [:max_redirects], max_requests: [:max_requests] ) end puts(format == 'jsonfeed' ? JSON.pretty_generate(result) : result) end |
#feed(yaml_file, feed_name = nil) ⇒ void
This method returns an undefined value.
54 55 56 57 58 59 60 |
# File 'lib/html2rss/cli.rb', line 54 def feed(yaml_file, feed_name = nil) config = Html2rss.config_from_yaml_file(yaml_file, feed_name) config[:params] = [:params] || {} apply_runtime_request_overrides!(config) puts(execute_feed { Html2rss.feed(config) }) end |
#schema ⇒ void
This method returns an undefined value.
Prints or writes the exported configuration JSON Schema.
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/html2rss/cli.rb', line 110 def schema schema_json = Html2rss::Config.json_schema_json(pretty: .fetch(:pretty, true)) if [:write] FileUtils.mkdir_p(File.dirname([:write])) File.write([:write], "#{schema_json}\n") puts [:write] return end puts schema_json end |
#validate(yaml_file, feed_name = nil) ⇒ void
This method returns an undefined value.
Validates a YAML config and prints the result.
135 136 137 138 139 140 141 |
# File 'lib/html2rss/cli.rb', line 135 def validate(yaml_file, feed_name = nil) result = Html2rss::Config.validate_yaml(yaml_file, feed_name, params: [:params] || {}) raise Thor::Error, "Invalid configuration: #{result.errors.to_h}" unless result.success? puts 'Configuration is valid' end |