danstis / rmstale

rmstale is a tool to remove stale files recursively below a given directory. Files and folders older than a defined period are removed.
MIT License
3 stars 1 forks source link

fix: update output of various commands #194

Closed danstis closed 8 months ago

danstis commented 8 months ago

User description

fixes #192, #193


Type

bug_fix, enhancement


Description


Changes walkthrough

Relevant files
Enhancement
rmstale.go
Enhance command-line usage output and version information handling

rmstale.go
  • Added a new function versionInfo to return version information.
  • Modified the main function to use flag.Usage for better command-line
    usage output.
  • Implemented a check to display usage information if no command-line
    arguments are provided.
  • Enhanced documentation for isEmpty function.
  • +21/-3   
    Tests
    rmstale_test.go
    Add unit test for version information output                         

    rmstale_test.go
  • Added a new test TestVersionInfo to verify the output of the
    versionInfo function.
  • +7/-0     

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

    sophie-syntax[bot] commented 8 months ago

    PR Description updated to latest commit (https://github.com/danstis/rmstale/commit/fc08bb9d707e0ec15772511a8fe6d92d8bbdb42f)

    sophie-syntax[bot] commented 8 months ago

    PR Review

    ⏱️ Estimated effort to review [1-5] 2, because the changes are straightforward and well-documented. The addition of a new function and the enhancement of command-line usage are clear and concise. The unit test added is relevant and directly related to the new functionality.
    🧪 Relevant tests Yes
    🔍 Possible issues Possible Bug: The check for no command-line arguments (`if flag.NFlag() == 0 && len(flag.Args()) == 0`) might not behave as expected in all cases. Consider scenarios where arguments are passed but not recognized by the flag package.
    Code Duplication: The removal of `flag.Usage` assignment in the original position and reassignment at the beginning might be unnecessary. If the intention was to ensure `flag.Usage` is set before any operation, consider leaving a comment explaining this choice.
    🔒 Security concerns No

    ✨ 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](https://pr-agent-docs.codium.ai/tools/review/#general-configurations) by configuring the tool. The tool can be triggered [automatically](https://pr-agent-docs.codium.ai/usage-guide/automations_and_usage/#github-app-automatic-tools-when-a-new-pr-is-opened) every time a new PR is opened, or can be invoked manually by commenting on any PR. - When commenting, to edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L23) related to the review tool (`pr_reviewer` section), use the following template: ``` /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=... ``` - With a [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/), use the following template: ``` [pr_reviewer] some_config1=... some_config2=... ``` See the review [usage page](https://pr-agent-docs.codium.ai/tools/review/) for a comprehensive guide on using this tool.
    sophie-syntax[bot] commented 8 months ago

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Maintainability
    Improve variable naming for readability. ___ **Consider using a more descriptive variable name instead of fp for the file path parameter
    in the procDir function. Descriptive names make the code more readable and maintainable.** [rmstale.go [100]](https://github.com/danstis/rmstale/pull/194/files#diff-8d2045f56d565d537deafa629d12ea2b52f0701a7366f155b4b1038745e58e4eR100-R100) ```diff -func procDir(fp, rootFolder string, age int, ext string) error { +func procDir(filePath, rootFolder string, age int, ext string) error { ```
    Best practice
    Use distinct variable names to avoid confusion. ___ **To avoid confusion and potential bugs, consider using a different variable name for the
    version flag. Using version for both a flag and a function call can be misleading.** [rmstale.go [49]](https://github.com/danstis/rmstale/pull/194/files#diff-8d2045f56d565d537deafa629d12ea2b52f0701a7366f155b4b1038745e58e4eR49-R49) ```diff -flag.BoolVar(&version, "version", false, "Display version information.") +flag.BoolVar(&showVersion, "version", false, "Display version information.") ```
    Handle and return errors from Readdir in the isEmpty function. ___ **To ensure that the isEmpty function accurately reports errors related to opening or
    reading a directory, consider handling and returning the error from Readdir as well.** [rmstale.go [148-149]](https://github.com/danstis/rmstale/pull/194/files#diff-8d2045f56d565d537deafa629d12ea2b52f0701a7366f155b4b1038745e58e4eR148-R149) ```diff f, err := os.Open(name) if err != nil { + return false, err +} +_, err = f.Readdir(1) +if err != nil && err != io.EOF { + return false, err +} ```
    Ensure file descriptors are properly closed to avoid leaks. ___ **To avoid potential issues with file descriptor leaks, ensure that the file opened in the
    isEmpty function is properly closed.** [rmstale.go [148-149]](https://github.com/danstis/rmstale/pull/194/files#diff-8d2045f56d565d537deafa629d12ea2b52f0701a7366f155b4b1038745e58e4eR148-R149) ```diff f, err := os.Open(name) if err != nil { + return false, err +} +defer f.Close() ```
    Enhancement
    Guide users to display help information when no arguments are provided. ___ **Since flag.Usage is overridden to print custom usage information, consider adding a
    message to guide users on how to display the help information when no arguments are
    provided.** [rmstale.go [58-60]](https://github.com/danstis/rmstale/pull/194/files#diff-8d2045f56d565d537deafa629d12ea2b52f0701a7366f155b4b1038745e58e4eR58-R60) ```diff if flag.NFlag() == 0 && len(flag.Args()) == 0 { + fmt.Println("No arguments provided. Use -h or --help to display usage information.") flag.Usage() return } ```

    ✨ 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](https://pr-agent-docs.codium.ai/usage-guide/automations_and_usage/#github-app-automatic-tools-when-a-new-pr-is-opened) every time a new PR is opened, or can be invoked manually by commenting on a PR. - When commenting, to edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L78) related to the improve tool (`pr_code_suggestions` section), use the following template: ``` /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=... ``` - With a [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/), use the following template: ``` [pr_code_suggestions] some_config1=... some_config2=... ``` See the improve [usage page](https://pr-agent-docs.codium.ai/tools/improve/) for a comprehensive guide on using this tool.
    sonarcloud[bot] commented 8 months ago

    Quality Gate Failed Quality Gate failed

    Failed conditions
    8.3% Coverage on New Code (required ≥ 60%)

    See analysis details on SonarCloud