Class: Kotoshu::Cli::AutoSetup
- Inherits:
-
Object
- Object
- Kotoshu::Cli::AutoSetup
- Defined in:
- lib/kotoshu/cli/auto_setup.rb
Overview
Interactive prompt that wraps the strict two-stage setup/resolve flow for the human-facing CLI.
The library API (‘Kotoshu.correct?`, `Kotoshu.suggest`) still raises `ResourceNotSetupError` strictly — no surprise downloads on metered networks. This class catches that error in the CLI dispatcher, asks the user once, and retries the original command. Programmatic users never see it.
Non-TTY contexts (pipes, CI) and offline mode never prompt. The caller decides how to surface a nil result — the CLI dispatcher raises Errors::ResourceUnavailable so scripts see stable exit codes.
Instance Method Summary collapse
-
#call(error, want: %i[spelling])) ⇒ String?
Prompt the user to set up the missing language.
-
#initialize(input: $stdin, output: $stderr) ⇒ AutoSetup
constructor
A new instance of AutoSetup.
Constructor Details
#initialize(input: $stdin, output: $stderr) ⇒ AutoSetup
Returns a new instance of AutoSetup.
22 23 24 25 |
# File 'lib/kotoshu/cli/auto_setup.rb', line 22 def initialize(input: $stdin, output: $stderr) @input = input @output = output end |
Instance Method Details
#call(error, want: %i[spelling])) ⇒ String?
Prompt the user to set up the missing language.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/kotoshu/cli/auto_setup.rb', line 33 def call(error, want: %i[spelling]) language = error.language return nil if skip_prompt? @output.puts (language, error.resource_type, want) answer = @input.gets&.strip&.downcase return nil unless affirmative?(answer) Kotoshu.setup(language, want: want) language end |