deggja / netfetch

Kubernetes tool for scanning clusters for network policies and identifying unprotected workloads.
MIT License
363 stars 23 forks source link

chore: refactor cli help message #139

Closed pehlicd closed 4 months ago

pehlicd commented 4 months ago

Hey,

First of all thanks for building such a good project. When I installed the netfetch and ran the help command I saw that the usage help message is duplicated as cobra generates it itself by default and this PR aims to refactor it.

Current version of the netfetch help message:

➜  netfetch git:(main) ✗ netfetch --help
Netfetch is a CLI tool that scans Kubernetes clusters for network policies
    and evaluates them against best practices. It helps in ensuring that your
    cluster's network configurations adhere to security standards.

    Usage:
    netfetch [command]

    Available Commands:
    scan            Scan Kubernetes namespaces for network policies
    scan namespace  Scan specific namespace in cluster
    dash            Open interactive dashboard
    help            Help about any command

    Flags:
    -h, --help   help for netfetch

Usage:
  netfetch [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  dash        Launch the Netfetch interactive dashboard
  help        Help about any command
  scan        Scan Kubernetes namespaces for network policies
  version     Print the version number of Netfetch

Flags:
  -h, --help   help for netfetch

Use "netfetch [command] --help" for more information about a command.

Updated version:

➜  netfetch git:(main) ✗ go run backend/main.go --help
Netfetch is a CLI tool that scans Kubernetes clusters for network policies
and evaluates them against best practices. It helps in ensuring that your
cluster's network configurations adhere to security standards.

Usage:
  netfetch [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  dash        Launch the Netfetch interactive dashboard
  help        Help about any command
  scan        Scan Kubernetes namespaces for network policies
  version     Print the version number of Netfetch

Flags:
  -h, --help   help for netfetch

Use "netfetch [command] --help" for more information about a command.
deggja commented 4 months ago

@pehlicd Perfect, thanks for the contribution. I have noticed this but did not get around to fixing it just yet. In addition to the fix you provide here, we should also update the help message, as more commands have been added to netfetch since this.

pehlicd commented 4 months ago

Hey @deggja, it is a pleasure to contribute to your project. What commands have been added, could you provide me with more info on this? Also, since the project uses cobra, there is no need to manually update the help messages as they are all automatically generated by the cobra package.

deggja commented 4 months ago

Hey @deggja, it is a pleasure to contribute to your project. What commands have been added, could you provide me with more info on this? Also, since the project uses cobra, there is no need to manually update the help messages as they are all automatically generated by the cobra package.

I had no idea Cobra did that to be fair. Regarding the missing commands/flags: It is possible to scan for both native k8s network policies when running netfetch scan by adding the flags --native and --cilium. I also just recently started adding the possibility to scan a specific policy by using the --target flag.

However, it seems like Cobra adds all this by default. Again, I had no clue. Which means thats already taken care off and you can disregard my previous comment.

pehlicd commented 4 months ago

You can find the related documentation in https://github.com/spf13/cobra/blob/main/site/content/user_guide.md#help-command also for the recently added flags they are also included in the help message as well you can find them by running netfetch scan --help. The reason that these flags are not shown in when help flag called in root command because the flags are specific to commands and subcommands 🙂