Skip to content
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

2297 cli parameters consistency #6028

Merged
merged 25 commits into from
Jan 9, 2024

Conversation

KasimirCash
Copy link
Contributor

Closes #2297

Changes proposed in this pull request:

We want to standardise flags used with CLI commands around the use of '-' rather than '_' while maintaining backward compatibility. To that end I've deprecated all flags using '_' in favour of an equivalent using '-' and introduced a check for the use of deprecated flags as well as logic to replace any used deprecated flags with their replacements. I've also scooped up some existing logic for CLI flag retrieval and validation and wrapped all this up into a parseCliParams() function. This way we can start to isolate some logic that otherwise is scattered throughout individual CLI commands.

If we're happy with the changes proposed here, then I could look at raising some related tickets such as extending use of parseCliParams() to other relevant CLI commands and looking at other opportunities for standardisation around validating CLI inputs as there is currently quite a bit of variation in how individual CLI commands handle similar work e.g. validating options associated with flags or updating config.

How to test the feature manually:

  1. Use either cli/do-install, cli/reconfigure, cli/create-user or cli/update-user with updated flags (e.g. --default-user admin --allow-anonymous) to see successful behaviour.
    image
    image

  2. Use deprecated flags (e.g. --default_user admin --allow_anonymous) to see successful behaviour with a deprecation warning.
    image
    image

  3. Use unknown flags (e.g. --defaultuser admin --allow_anon)to trigger expected warning and failure.
    image
    image

Pull request checklist:

  • clear commit messages
  • code manually tested
  • unit tests written (optional if too hard)
  • documentation updated

Copy link
Member

@aledeg aledeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested it but it seems alright. Good job.

cli/_cli.php Outdated
/**
* Parses perameters used with FreshRSS' CLI commands.
* @param array{'valid':array<string,string>,'deprecated':array<string,string>} $parameters An array of 'valid': An
* array of perameters as keys and their respective getopt() notations as values. 'deprecated' An array with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* array of perameters as keys and their respective getopt() notations as values. 'deprecated' An array with
* array of parameters as keys and their respective getopt() notations as values. 'deprecated' An array with

There are multiple instances of parameters. Please replace them by parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fixed now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't believe I forgot how to spell parameters...

@Alkarex Alkarex added this to the 1.24.0 milestone Jan 7, 2024
@Alkarex Alkarex added the CLI Command line interfaces in ./cli label Jan 7, 2024
@Alkarex
Copy link
Member

Alkarex commented Jan 9, 2024

Hello and thanks for the PR 👍🏻
If possible, please allow edits; example from another PR:

image

cli/_cli.php Outdated Show resolved Hide resolved
cli/_cli.php Outdated Show resolved Hide resolved
@Alkarex Alkarex merged commit 9a80dde into FreshRSS:edge Jan 9, 2024
2 checks passed
@KasimirCash KasimirCash deleted the 2297-cli-parameters-consistency branch January 10, 2024 09:01
@KasimirCash
Copy link
Contributor Author

@Alkarex, @aledeg Thanks for the feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI Command line interfaces in ./cli
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI parameters consistency
3 participants