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

Feat: man page #1089

Merged
merged 4 commits into from
Apr 10, 2024
Merged

Feat: man page #1089

merged 4 commits into from
Apr 10, 2024

Conversation

fujiapple852
Copy link
Owner

@fujiapple852 fujiapple852 commented Apr 5, 2024

User description

Closes #85


Type

enhancement, documentation


Description

  • Added support for generating a man page with the --generate-man command.
  • Implemented man page generation logic in src/main.rs.
  • Added clap_mangen dependency for man page generation.
  • Updated command line argument parsing to support the new --generate-man option.
  • Documented the new man page generation feature in README.md and CHANGELOG.md.
  • Updated shell completions (bash, elvish, fish, PowerShell, zsh) to include the --generate-man option.

Changes walkthrough

Relevant files
Enhancement
8 files
config.rs
Support for Generating Man Page in Application Logic         

src/config.rs

  • Added PrintManPage variant to TrippyAction enum.
  • Updated TrippyAction::from to handle generate_man argument.
  • +4/-0     
    cmd.rs
    Command Line Argument Parsing for Man Page Generation       

    src/config/cmd.rs

  • Added generate_man field to Args struct to support --generate-man
    command.
  • Updated targets argument to be optional if --generate-man is used.
  • +5/-1     
    main.rs
    Man Page Generation and Printing Implementation                   

    src/main.rs

  • Implemented print_man_page function to generate and print the man
    page.
  • Added man_page function to generate man page content.
  • Updated main function to handle PrintManPage action.
  • +14/-0   
    completions_bash.txt
    Updated Bash Completions for Man Page Generation                 

    test_resources/config/completions_bash.txt

    • Updated bash completions to include --generate-man option.
    +1/-1     
    completions_elvish.txt
    Updated Elvish Completions for Man Page Generation             

    test_resources/config/completions_elvish.txt

    • Updated elvish completions to include --generate-man option.
    +1/-0     
    completions_fish.txt
    Updated Fish Completions for Man Page Generation                 

    test_resources/config/completions_fish.txt

    • Updated fish completions to include --generate-man option.
    +1/-0     
    completions_powershell.txt
    Updated PowerShell Completions for Man Page Generation     

    test_resources/config/completions_powershell.txt

    • Updated PowerShell completions to include --generate-man option.
    +1/-0     
    completions_zsh.txt
    Updated Zsh Completions for Man Page Generation                   

    test_resources/config/completions_zsh.txt

    • Updated zsh completions to include --generate-man option.
    +1/-0     
    Documentation
    3 files
    CHANGELOG.md
    Updated CHANGELOG for Man Page Generation Feature               

    CHANGELOG.md

  • Documented the addition of --generate-man flag for generating ROFF man
    page.
  • +1/-0     
    README.md
    Documented Man Page Generation in README                                 

    README.md

  • Documented how to generate the ROFF man page using --generate-man.
  • +9/-0     
    man_page.1
    New Man Page File for the Application                                       

    test_resources/config/man_page.1

    • Added a new man page file for the application.
    +352/-0 
    Dependencies
    1 files
    Cargo.toml
    Added Dependency for Man Page Generation                                 

    Cargo.toml

    • Added clap_mangen dependency for man page generation.
    +1/-0     

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link

    github-actions bot commented Apr 5, 2024

    PR Description updated to latest commit (2056fa0)

    Copy link

    github-actions bot commented Apr 5, 2024

    PR Review

    🧪 Relevant tests

    No

    🔍 Possible issues

    No

    🔒 Security concerns

    No

    Code feedback:
    relevant filesrc/config.rs
    suggestion      

    Consider adding a match arm for PrintManPage in the TrippyAction::from method to ensure exhaustive matching and future-proofing. This will help maintain the code's robustness if more actions are added in the future. [important]

    relevant line} else if args.generate_man {

    relevant filesrc/config/cmd.rs
    suggestion      

    For better maintainability, consider using a constant for the generate_man string literal used in the #[arg(long)] attribute. This will make future updates easier and reduce the risk of typos in multiple places. [medium]

    relevant line#[arg(long)]

    relevant filesrc/main.rs
    suggestion      

    To improve error handling, consider adding specific error messages in print_man_page and man_page functions for scenarios where operations might fail, such as generating the man page or converting bytes to String. This will enhance the user's understanding of what went wrong. [important]

    relevant lineprintln!("{}", man_page()?);

    relevant fileCargo.toml
    suggestion      

    Ensure that the clap_mangen version specified is compatible with other dependencies and the project's Rust edition. It might be beneficial to check if there's a newer version available that could offer more features or improvements. [medium]

    relevant lineclap_mangen = "0.2.20"


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.

    The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.

    • When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:
    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    
    [pr_reviewer]
    some_config1=...
    some_config2=...
    

    See the review usage page for a comprehensive guide on using this tool.

    Copy link

    github-actions bot commented Apr 5, 2024

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Enhancement
    Add error handling for man page generation failures.

    Consider handling the case where generating the man page might fail due to various reasons
    (e.g., file system permissions, unavailable resources). This can be done by adding an
    error variant to the TrippyAction enum to capture and handle such failures gracefully.

    src/config.rs [258]

    -PrintManPage,
    +PrintManPage(Result<(), Error>),
     
    Enhance user help message for man page generation.

    To improve the user experience, consider adding a more descriptive help message for the
    generate_man argument, explaining what the man page includes or how it can be used.

    src/config/cmd.rs [245]

    -#[arg(long)]
    +#[arg(long, help = "Generate a ROFF man page detailing the usage and options of the trip command")]
     pub generate_man: bool,
     
    Add brief explanations for each option in the SYNOPSIS section.

    Consider adding a brief explanation for each option in the SYNOPSIS section to improve
    clarity and user understanding. Currently, the options are listed without descriptions,
    which might be overwhelming for new users.

    test_resources/config/man_page.1 [7]

    -\fBtrip\fR [\fB\-c\fR|\fB\-\-config\-file\fR] [\fB\-m\fR|\fB\-\-mode\fR] [\fB\-u\fR|\fB\-\-unprivileged\fR] [\fB\-p\fR|\fB\-\-protocol\fR] [\fB\-\-udp\fR] [\fB\-\-tcp\fR] [\fB\-\-icmp\fR] [\fB\-F\fR|\fB\-\-addr\-family\fR] [\fB\-4\fR|\fB\-\-ipv4\fR] [\fB\-6\fR|\fB\-\-ipv6\fR] [\fB\-P\fR|\fB\-\-target\-port\fR] [\fB\-S\fR|\fB\-\-source\-port\fR] [\fB\-A\fR|\fB\-\-source\-address\fR] [\fB\-I\fR|\fB\-\-interface\fR] [\fB\-i\fR|\fB\-\-min\-round\-duration\fR] [\fB\-T\fR|\fB\-\-max\-round\-duration\fR] [\fB\-g\fR|\fB\-\-grace\-duration\fR] [\fB\-\-initial\-sequence\fR] [\fB\-R\fR|\fB\-\-multipath\-strategy\fR] [\fB\-U\fR|\fB\-\-max\-inflight\fR] [\fB\-f\fR|\fB\-\-first\-ttl\fR] [\fB\-t\fR|\fB\-\-max\-ttl\fR] [\fB\-\-packet\-size\fR] [\fB\-\-payload\-pattern\fR] [\fB\-Q\fR|\fB\-\-tos\fR] [\fB\-e\fR|\fB\-\-icmp\-extensions\fR] [\fB\-\-read\-timeout\fR] [\fB\-r\fR|\fB\-\-dns\-resolve\-method\fR] [\fB\-y\fR|\fB\-\-dns\-resolve\-all\fR] [\fB\-\-dns\-timeout\fR] [\fB\-z\fR|\fB\-\-dns\-lookup\-as\-info\fR] [\fB\-a\fR|\fB\-\-tui\-address\-mode\fR] [\fB\-\-tui\-as\-mode\fR] [\fB\-\-tui\-custom\-columns\fR] [\fB\-\-tui\-icmp\-extension\-mode\fR] [\fB\-\-tui\-geoip\-mode\fR] [\fB\-M\fR|\fB\-\-tui\-max\-addrs\fR] [\fB\-s\fR|\fB\-\-tui\-max\-samples\fR] [\fB\-\-tui\-max\-flows\fR] [\fB\-\-tui\-preserve\-screen\fR] [\fB\-\-tui\-refresh\-rate\fR] [\fB\-\-tui\-privacy\-max\-ttl\fR] [\fB\-\-tui\-theme\-colors\fR] [\fB\-\-print\-tui\-theme\-items\fR] [\fB\-\-tui\-key\-bindings\fR] [\fB\-\-print\-tui\-binding\-commands\fR] [\fB\-C\fR|\fB\-\-report\-cycles\fR] [\fB\-G\fR|\fB\-\-geoip\-mmdb\-file\fR] [\fB\-\-generate\fR] [\fB\-\-generate\-man\fR] [\fB\-\-print\-config\-template\fR] [\fB\-\-log\-format\fR] [\fB\-\-log\-filter\fR] [\fB\-\-log\-span\-events\fR] [\fB\-v\fR|\fB\-\-verbose\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fITARGETS\fR]
    +\fBtrip\fR [\fB\-c\fR|\fB\-\-config\-file\fR <config file path>] [\fB\-m\fR|\fB\-\-mode\fR <output mode>] [\fB\-u\fR|\fB\-\-unprivileged\fR] [\fB\-p\fR|\fB\-\-protocol\fR <protocol>] ... [\fB\-V\fR|\fB\-\-version\fR] [\fITARGETS\fR <list of targets>]
     
    Best practice
    Improve error handling in man page generation.

    Since print_man_page() involves IO operations that might fail, ensure that any errors are
    logged or handled appropriately within the function to avoid silent failures.

    src/main.rs [107]

    -println!("{}", man_page()?);
    +match man_page() {
    +    Ok(page) => println!("{}", page),
    +    Err(e) => log::error!("Failed to generate man page: {}", e),
    +}
     
    Verify compatibility of clap_mangen dependency.

    Ensure that the version of clap_mangen used is compatible with other dependencies and the
    project's Rust edition to avoid potential compatibility issues.

    Cargo.toml [59]

    -clap_mangen = "0.2.20"
    +clap_mangen = "0.2.20" # Ensure compatibility with project's Rust edition and other dependencies
     
    Maintainability
    Refactor command-line argument parsing to use match statements.

    For consistency and future-proofing, consider using a match statement instead of
    sequential if-else statements when determining the TrippyAction based on command-line
    arguments. This approach can make adding new actions more straightforward and the code
    easier to read.

    src/config.rs [271-272]

    -} else if args.generate_man {
    -    Self::PrintManPage
    +match args {
    +    _ if args.generate_man => Self::PrintManPage,
    +    _ if let Some(shell) = args.generate => Self::PrintShellCompletions(shell),
    +    _ => Self::Trippy(TrippyConfig::from(args, platform)?),
    +}
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

    • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    @fujiapple852 fujiapple852 force-pushed the feat-man-page branch 3 times, most recently from 85ea022 to d216aaa Compare April 10, 2024 11:45
    @fujiapple852 fujiapple852 merged commit 8ed3000 into master Apr 10, 2024
    18 checks passed
    @fujiapple852 fujiapple852 deleted the feat-man-page branch April 10, 2024 12:55
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    Generation of man pages
    1 participant