Module: W3cApi::Commands::UserAgentOption
- Included in:
- Affiliation, Ecosystem, Group, Participation, Series, Specification, SpecificationVersion, Translation, User
- Defined in:
- lib/w3c_api/commands/user_agent_option.rb
Overview
Adds a --user-agent flag to a command class and applies it before the command runs. Thor cannot parse options that precede a subcommand name, so the flag lives on each command class rather than on the root Cli:
w3c_api specification fetch --user-agent "my-crawler/1.0 (+url)"
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/w3c_api/commands/user_agent_option.rb', line 13 def self.included(base) base.class_option :user_agent, type: :string, desc: "User-Agent sent to api.w3.org " \ "(default: #{Hal::DEFAULT_USER_AGENT})" end |
Instance Method Details
#initialize(*args) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/w3c_api/commands/user_agent_option.rb', line 20 def initialize(*args) super # Configure before the command body builds a Client: changing the user # agent rebuilds the connection, client and register. Hal.instance.configure_user_agent([:user_agent]) if [:user_agent] end |