Open
Conversation
57977a6 to
7e84aeb
Compare
Adds `onboard` (alias `init`) subcommand with a styled interactive setup wizard that creates the config directory/file and walks the user through preferences.
- Upgrade dialoguer 0.11 -> 0.12, console 0.15 -> 0.16 - Use interact_opt() on all Confirm prompts for consistent Escape-to-cancel behavior - Replace custom urlencoded() with url::Url::parse_with_params for reliable URL construction and encoding - Skip auto-location prompt after city search (intent is clear) - Use &Path instead of &PathBuf in Config::save() and load_from_path()
… harden config - Fix city search discarding `city`, `display`, and `city_name_language` fields - Add prompts for location display mode and city name language - Warn on corrupted config instead of silently replacing with defaults - Make `Config::save()` create parent directories - Replace `console` with `crossterm::style::Stylize` for styling - Replace `url::Url` with `reqwest::Url`, remove redundant deps - Reuse HTTP client across city search calls - Install rustls provider early in `main()` to fix bare `cargo run` panic
235868b to
e7e4719
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
onboardsubcommand (alias:init) that replaces the current manual config setup with a styled, interactive setup wizard.Before this change, users had to manually create the config directory and write a TOML file by hand. Now they can run:
What changed
New files:
src/onboard.rs-- the full onboarding flow: prompts, geocoding integration, styled output, config save.Modified files:
Cargo.toml-- addeddialoguer(interactive prompts with fuzzy-select).src/main.rs-- converted flat CLI to optional subcommand via clap's#[command(subcommand)]. Existing flags and behavior are untouched when no subcommand is given. Rustls crypto provider is now installed at startup to cover all HTTP code paths (geolocation, onboard, weather).src/config.rs-- addedSerializetoConfigandLocation. Addedsave()(creates parent dirs automatically),get_config_dir()methods. Madeget_config_path()andvalidate()public.src/weather/types.rs-- addedSerializetoWeatherUnits.src/error.rs-- addedOnboardErrorenum. AddedWriteErrorandSerializeErrorvariants toConfigError.src/lib.rs-- registered the newonboardmodule.New dependencies
dialoguerfuzzy-select)Select,FuzzySelect,Input,Confirminteractive promptsTerminal styling uses
crossterm::style::Stylize(already a project dependency). URL construction usesreqwest::Url::parse_with_params(re-exported from theurlcrate thatreqwestalready depends on). No additional direct dependencies needed for either.How it works
The wizard runs in three phases:
Phase 1 -- Directory and file setup
Resolves the platform-specific config path and loads the existing config file if present. If the file exists but is corrupted, a warning is printed and defaults are used. Falls back to
Config::default()if no file exists. Directory creation is handled byConfig::save()automatically.Phase 2 -- Interactive prompts
Walks through every config setting with styled prompts. Existing values are shown as defaults -- pressing Enter keeps them.
Prompt sequence:
Select): Enter coordinates / Search by city name / Use auto-detectionInput<f64>with validation) or City search (text input → Open-Meteo Geocoding API →FuzzySelectfrom results). City search automatically sets the city name and switches display mode to "City".Confirm, coordinates path only): Enable IP-based auto-detection? Skipped after city search since the user explicitly chose a location.Select): Coordinates only / City name / Both (city + coordinates)Input): Language code for city names in the HUD (default: "auto" = system locale)Confirm): Hide coordinates in the UI?Select): Celsius / FahrenheitSelect): km/h / m/s / mph / knotsSelect): mm / inchConfirm): Hide the status line?Confirm): Suppress non-error output?A single
reqwest::Clientis created once and reused across city search calls within the wizard.Phase 3 -- Save and finish
Validates the final config, serializes with
toml::to_string_pretty(), writes to the config path (creating parent directories if needed), and prints a success message.City search via Geocoding API
When the user chooses "Search by city name", the wizard:
GET https://geocoding-api.open-meteo.com/v1/search?name=...&count=10&language=en).City, Region, Country (lat, lon) - pop. N.reqwest::Url::parse_with_params.city, setsdisplay = "city", and preserves the existingcity_name_languagesetting.Sample output
Welcome banner and location prompt:
City search results:
Location display and units:
Completion:
Edge cases covered
Config::save()Config::default(), creates file on saveConfig::default()999)reqwest::UrlBackward compatibility
./config.toml> XDG path) is unchanged.Screenshots
Initial
City search
Example of units selection
Full onboarding log after completion