Class: Html2rss::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/html2rss/cli.rb

Overview

The Html2rss command line interface.

Constant Summary collapse

AUTO_FALLBACK_CHAIN =

Ordered fallback chain attempted by the feed-level :auto plan.

Returns:

  • (Array<Symbol>)
Html2rss::FeedPipeline::AutoFallback::CHAIN.freeze
STRATEGY_OPTION_ENUM =

Supported CLI strategy plan option values (:auto plus concrete strategies).

Returns:

  • (Array<String>)
Html2rss::FeedPipeline::StrategyPlan.accepted_names.map(&:to_s).freeze
STRATEGY_OPTION_DESC =

User-facing strategy help text that reflects the current fallback chain.

Returns:

  • (String)
[
  'Optional request strategy (defaults to auto; auto tries',
  "#{AUTO_FALLBACK_CHAIN.join(' -> ')})"
].join(' ').freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns whether Thor should terminate process on command failures.

Returns:

  • (Boolean)

    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 = nil) ⇒ void

This method returns an undefined value.

Parameters:

  • url (String, nil) (defaults to: nil)

    source page URL for auto discovery



91
92
93
94
95
96
97
98
99
100
# File 'lib/html2rss/cli.rb', line 91

def auto(url = nil)
  format = options.fetch(:format, 'rss')
  strategy, local_file_path, url = prepare_auto_inputs(url, options[:input])

  result = execute_feed do
    source_call(url, strategy, local_file_path, format == 'jsonfeed')
  end

  puts(format == 'jsonfeed' ? JSON.pretty_generate(result) : result)
end

#capture(url = nil) ⇒ void

This method returns an undefined value.

Captures a URL and prints a reusable YAML config.

Parameters:

  • url (String, nil) (defaults to: nil)

    source page URL for capture



125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/html2rss/cli.rb', line 125

def capture(url = nil) # rubocop:disable Metrics/MethodLength
  strategy, local_file_path, url = prepare_auto_inputs(url, options[:input])
  config = Html2rss.capture(
    url,
    strategy:,
    items_selector: options[:items_selector],
    limit: options[:limit]&.to_i,
    max_redirects: options[:max_redirects],
    max_requests: options[:max_requests],
    local_file_path:
  )
  puts YAML.dump(HashUtil.deep_stringify_keys(config))
end

#feed(yaml_file, feed_name = nil) ⇒ void

This method returns an undefined value.

Parameters:

  • yaml_file (String)

    path to YAML config

  • feed_name (String, nil) (defaults to: nil)

    optional named feed in multi-feed config



57
58
59
60
61
62
63
64
# File 'lib/html2rss/cli.rb', line 57

def feed(yaml_file, feed_name = nil)
  config = Html2rss.config_from_yaml_file(yaml_file, feed_name)
  config[:params] = options[:params] || {}
  apply_runtime_request_overrides!(config)
  apply_local_file_input!(config, options[:input]) if options[:input]

  puts(execute_feed { Html2rss.feed(config) })
end

#mcpvoid

This method returns an undefined value.

Starts the MCP server for AI client consumption.



178
179
180
181
182
183
# File 'lib/html2rss/cli.rb', line 178

def mcp
  Html2rss::MCP.start(
    transport: options[:transport].to_sym,
    port: options[:port]
  )
end

#schemavoid

This method returns an undefined value.

Prints or writes the exported configuration JSON Schema.



151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/html2rss/cli.rb', line 151

def schema
  schema_json = Html2rss::Config.json_schema_json(pretty: options.fetch(:pretty, true))

  if options[:write]
    FileUtils.mkdir_p(File.dirname(options[:write]))
    File.write(options[:write], "#{schema_json}\n")
    puts options[: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.

Parameters:

  • yaml_file (String)

    the YAML file to validate

  • feed_name (String, nil) (defaults to: nil)

    optional feed name for multi-feed files

Raises:

  • (Thor::Error)


197
198
199
200
201
202
203
# File 'lib/html2rss/cli.rb', line 197

def validate(yaml_file, feed_name = nil)
  result = Html2rss::Config.validate_yaml(yaml_file, feed_name, params: options[:params] || {})

  raise Thor::Error, "Invalid configuration: #{result.errors.to_h}" unless result.success?

  puts 'Configuration is valid'
end