Class: Html2rss::CLI
- Inherits:
-
Thor
- Object
- Thor
- Html2rss::CLI
- Defined in:
- lib/html2rss/cli.rb
Overview
The Html2rss command line interface.
Constant Summary collapse
- STRATEGY_OPTION_ENUM =
Supported CLI strategy plan option values (:auto plus concrete strategies).
Html2rss::FeedPipeline::StrategyPlan.accepted_names.map(&:to_s).freeze
- STRATEGY_OPTION_DESC =
User-facing strategy help text that reflects the current fallback chain.
[ 'Optional request strategy (defaults to auto; auto tries', "#{Html2rss::FeedPipeline::AutoFallback::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 = nil) ⇒ void
-
#capture(url = nil) ⇒ void
Captures a URL and prints a reusable YAML config.
- #feed(yaml_file, feed_name = nil) ⇒ void
-
#mcp ⇒ void
Starts the MCP server for AI client consumption.
-
#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.
26 27 28 |
# File 'lib/html2rss/cli.rb', line 26 def self.exit_on_failure? true end |
Instance Method Details
#auto(url = nil) ⇒ void
This method returns an undefined value.
90 91 92 93 94 95 96 97 |
# File 'lib/html2rss/cli.rb', line 90 def auto(url = nil) format = .fetch(:format, 'rss') strategy, local_file_path, url = prepare_auto_inputs(url, [:input]) feed_result = execute_feed { auto_feed_result_for(url, strategy, local_file_path) } explain_status!(feed_result.status) if [:explain] puts(format == 'jsonfeed' ? JSON.pretty_generate(feed_result.to_json_feed) : feed_result.to_rss) end |
#capture(url = nil) ⇒ void
This method returns an undefined value.
Captures a URL and prints a reusable YAML config.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/html2rss/cli.rb', line 126 def capture(url = nil) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength -- CLI option wiring strategy, local_file_path, url = prepare_auto_inputs(url, [:input]) result = Html2rss::Capture.build( url, strategy:, items_selector: [:items_selector], limit: [:limit]&.to_i, max_redirects: [:max_redirects], max_requests: [:max_requests], local_file_path: ) explain_capture!(result) if [:explain] puts Config.to_yaml(result.config) end |
#feed(yaml_file, feed_name = nil) ⇒ void
This method returns an undefined value.
52 53 54 55 56 57 58 59 |
# File 'lib/html2rss/cli.rb', line 52 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) apply_local_file_input!(config, [:input]) if [:input] puts(execute_feed { Html2rss.feed(config) }) end |
#mcp ⇒ void
This method returns an undefined value.
Starts the MCP server for AI client consumption.
180 181 182 183 184 185 |
# File 'lib/html2rss/cli.rb', line 180 def mcp Html2rss::MCP.start( transport: [:transport].to_sym, port: [:port] ) end |
#schema ⇒ void
This method returns an undefined value.
Prints or writes the exported configuration JSON Schema.
153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/html2rss/cli.rb', line 153 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.
199 200 201 202 203 204 205 |
# File 'lib/html2rss/cli.rb', line 199 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 |