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

Fix gzip help text #2060

Merged
merged 3 commits into from
Sep 14, 2024
Merged

Fix gzip help text #2060

merged 3 commits into from
Sep 14, 2024

Conversation

DL6ER
Copy link
Member

@DL6ER DL6ER commented Sep 10, 2024

What does this implement/fix?

The previously described flags --compress and --uncompress never existed.

New help text:

image


Related issue or feature (if applicable): N/A

Pull request in docs with documentation (if applicable): N/A


By submitting this pull request, I confirm the following:

  1. I have read and understood the contributors guide, as well as this entire template. I understand which branch to base my commits and Pull Requests against.
  2. I have commented my proposed changes within the code.
  3. I am willing to help maintain this change if there are issues with it later.
  4. It is compatible with the EUPL 1.2 license
  5. I have squashed any insignificant commits. (git rebase)

Checklist:

  • The code change is tested and works locally.
  • I based my code and PRs against the repositories developmental branch.
  • I signed off all commits. Pi-hole enforces the DCO for all contributions
  • I signed all my commits. Pi-hole requires signatures to verify authorship
  • I have read the above and my PR is ready for review.

Signed-off-by: DL6ER <[email protected]>
@DL6ER
Copy link
Member Author

DL6ER commented Sep 10, 2024

The corresponding code is here:

FTL/src/args.c

Lines 215 to 266 in 3b1aebd

// Compression feature
if((argc == 3 || argc == 4) &&
(strcmp(argv[1], "gzip") == 0 || strcmp(argv[1], "--gzip") == 0))
{
// Enable stdout printing
cli_mode = true;
log_ctrl(false, true);
// Get input and output file names
const char *infile = argv[2];
bool is_gz = strEndsWith(infile, ".gz");
char *outfile = NULL;
if(argc == 4)
{
// If an output file is given, we use it
outfile = strdup(argv[3]);
}
else if(is_gz)
{
// If no output file is given, and this is a gzipped
// file, we use the input file name without ".gz"
// appended
outfile = calloc(strlen(infile)-2, sizeof(char));
memcpy(outfile, infile, strlen(infile)-3);
}
else
{
// If no output file is given, and this is not a gzipped
// file, we use the input file name with ".gz" appended
outfile = calloc(strlen(infile)+4, sizeof(char));
strcpy(outfile, infile);
strcat(outfile, ".gz");
}
bool success = false;
if(is_gz)
{
// If the input file is already gzipped, we decompress it
success = inflate_file(infile, outfile, true);
}
else
{
// If the input file is not gzipped, we compress it
success = deflate_file(infile, outfile, true);
}
// Free allocated memory
free(outfile);
// Return exit code
exit(success ? EXIT_SUCCESS : EXIT_FAILURE);
}

Co-authored-by: RD WebDesign <[email protected]>
Signed-off-by: Dominik <[email protected]>
@DL6ER DL6ER requested review from rdwebdesign and a team September 14, 2024 08:29
Copy link
Member

@yubiuser yubiuser left a comment

Choose a reason for hiding this comment

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

I understand the changed help text, but it required a lot of mental energy. The whole reason for the change is

The previously described flags --compress and --uncompress never existed.

I'd like to suggest to implement them. This would make the handling way more intuitive and does not require to think around the corner.

pihole-FTL --gzip --compress file.txt --> file.txt.gz
pihole-FTL --gzip --compress file.txt out.gt--> out.gz
pihole-FTL --gzip --compress file.gz --> error/or file.gz.gz
pihole-FTL --gzip --uncompress file.txt.gz --> file.txt
pihole-FTL --gzip --uncompress file.txt --> error
pihole-FTL --gzip file.txt --> error
pihole-FTL --gzip file.gz --> error

@DL6ER
Copy link
Member Author

DL6ER commented Sep 14, 2024

Sometimes - actually quite often - less is more.

I would like to avoid introducing additional flags because shorter always seems to be better on the CLI. Of course, this is only true if understandability isn't decreased by this brevity. But I don't really think it's the case here. How about instead of describing its precisely, we instead only provide the examples and let them speak for themselves?

Like
image

@yubiuser
Copy link
Member

Your suggestion sounds good. The text is short and easy to understand.

@DL6ER DL6ER requested a review from yubiuser September 14, 2024 19:40
@DL6ER DL6ER enabled auto-merge September 14, 2024 19:51
@DL6ER DL6ER merged commit bcb77ef into development Sep 14, 2024
17 checks passed
@DL6ER DL6ER deleted the fix/help_gzip branch September 14, 2024 19:58
@PromoFaux PromoFaux mentioned this pull request Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants