-
-
Notifications
You must be signed in to change notification settings - Fork 2
Add CLI options to avoid interactive prompts #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
On launch, you can now provide the following: ```bash Usage: whatsapp [OPTIONS]+ Options: -u, --url WhatsApp functions endpoint -n, --number=VALUE Your WhatsApp user phone number -j, --json Format output as JSON -t, --text Format output as text -y, --yaml Format output as YAML -?, -h, --help Display this help. -v, --version Render tool version and updates. ``` Upon starting, if any of the options don't have values, user will get asked for them interactively. Upon choosing a value, it's persisted to the global `~\.netconfig` and never asked again. It can always be overriden (and auto-updated) via the option(s) again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds new CLI options to avoid interactive prompts by allowing users to provide configuration values (WhatsApp endpoint, phone number, and output format) via command line arguments, which are also persisted for future use.
- Updated Program.cs to parse new CLI options and update the global config.
- Modified Interactive.cs to prompt for missing configuration values.
- Introduced the ConsoleOption class to handle CLI parsing and added corresponding tests and documentation in readme.md.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Console/Properties/launchSettings.json | Updated launch arguments for easier local testing of CLI help output. |
| src/Console/Program.cs | Added CLI options parsing and config persistence logic. |
| src/Console/OutputFormat.cs | Introduced output format enum to support new formatting options. |
| src/Console/Interactive.cs | Modified interactive prompts based on missing config values. |
| src/Console/ConsoleOption.cs | Created CLI option parsing using Mono.Options with new syntax. |
| src/Console/Console.csproj | Added Mono.Options package reference. |
| readme.md | Updated documentation to reflect the new CLI usage. |
src/Console/Interactive.cs
Outdated
| readonly CancellationTokenSource cts = new(); | ||
|
|
||
| string? serviceEndpoint = configuration["WhatsApp:Endpoint"]; | ||
| string? service = configuration["WhatsApp:Endpoint"]; |
Copilot
AI
Jun 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a potential configuration key mismatch: Program.cs writes to the key 'whatsapp' while Interactive.cs reads from 'WhatsApp:Endpoint'. Normalize the key casing across the codebase to avoid issues.
|
|
||
| public int? Number { get; private set; } | ||
|
|
||
| static int ParseNumber(string value) => int.Parse([.. value.Where(char.IsDigit)]); |
Copilot
AI
Jun 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider adding validation or using TryParse to handle cases where the input string might not contain any digits, avoiding potential runtime exceptions.
| static int ParseNumber(string value) => int.Parse([.. value.Where(char.IsDigit)]); | |
| static int? ParseNumber(string value) | |
| { | |
| var digits = new string(value.Where(char.IsDigit).ToArray()); | |
| if (string.IsNullOrEmpty(digits)) | |
| return null; | |
| return int.TryParse(digits, out var result) ? result : null; | |
| } |
🧪 Details on Ubuntu 24.04.2 LTSfrom dotnet-retest v0.7.1 on .NET 8.0.17 with 💜 by @devlooped |
Even though config is case insensitive when reading.
On launch, you can now provide the following:
Usage: whatsapp [OPTIONS]+ Options: -u, --url WhatsApp functions endpoint -n, --number=VALUE Your WhatsApp user phone number -j, --json Format output as JSON -t, --text Format output as text -y, --yaml Format output as YAML -?, -h, --help Display this help. -v, --version Render tool version and updates.Upon starting, if any of the options don't have values, user will get asked for them interactively. Upon choosing a value, it's persisted to the global
~\.netconfigand never asked again. It can always be overriden (and auto-updated) via the option(s) again.