Skip to content

Conversation

@kzu
Copy link
Member

@kzu kzu commented Jun 21, 2025

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 ~\.netconfig and never asked again. It can always be overriden (and auto-updated) via the option(s) again.

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.
@kzu kzu requested review from adalon and Copilot June 21, 2025 23:15
@kzu kzu added the enhancement New feature or request label Jun 21, 2025
Copy link

Copilot AI left a 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.

readonly CancellationTokenSource cts = new();

string? serviceEndpoint = configuration["WhatsApp:Endpoint"];
string? service = configuration["WhatsApp:Endpoint"];
Copy link

Copilot AI Jun 21, 2025

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.

Copilot uses AI. Check for mistakes.

public int? Number { get; private set; }

static int ParseNumber(string value) => int.Parse([.. value.Where(char.IsDigit)]);
Copy link

Copilot AI Jun 21, 2025

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.

Suggested change
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;
}

Copilot uses AI. Check for mistakes.
@kzu
Copy link
Member Author

kzu commented Jun 21, 2025

36 passed 36 passed 7 skipped

🧪 Details on Ubuntu 24.04.2 LTS

from dotnet-retest v0.7.1 on .NET 8.0.17 with 💜 by @devlooped

kzu added 2 commits June 21, 2025 20:17
Even though config is case insensitive when reading.
@kzu kzu enabled auto-merge (rebase) June 21, 2025 23:22
@kzu kzu merged commit de4076c into main Jun 21, 2025
7 checks passed
@kzu kzu deleted the dev/CliOptions branch June 21, 2025 23:24
@devlooped devlooped locked and limited conversation to collaborators Jul 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants