Skip to content

Commit

Permalink
Add command line flags and update README
Browse files Browse the repository at this point in the history
* Add command line flags for various configuration options in `cmd/root.go`
* Bind each flag to its corresponding Viper configuration in the `init` function
* Update `setDefaultConfigValues` function to set default values for new configuration options
* Add single letter flag aliases for each command line flag
* Update `README.md` to include new command line flags and mention `--help` and `--version` flags
  • Loading branch information
unclesp1d3r committed Oct 2, 2024
1 parent 71f46e2 commit 42a48fa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,25 @@ Optional configuration options for using the ZAP feature with a shared directory
The agent will automatically create a configuration file in the same directory as the agent (`cipherswarmagent.yaml`)
with the provided configuration options and default options that can be modified.

### Command Line Flags

The agent can also be configured using command line flags. The following flags are available:

- `--api_token` or `-a`: The API token for the CipherSwarm server.
- `--api_url` or `-u`: The URL of the CipherSwarm server.
- `--data_path` or `-p`: The path to the directory where the agent will store data.
- `--gpu_temp_threshold` or `-g`: The temperature threshold for the GPU in degrees Celsius.
- `--always_use_native_hashcat` or `-n`: Force using the native hashcat binary.
- `--sleep_on_failure` or `-s`: Duration of sleep after a task failure.
- `--files_path` or `-f`: The path to the directory where the agent will store task files.
- `--extra_debugging` or `-e`: Enable additional debugging information.
- `--status_timer` or `-t`: Interval in seconds for sending status updates to the server.
- `--write_zaps_to_file` or `-w`: Write zap output to a file in the zaps directory.
- `--zap_path` or `-z`: The path to the directory where the agent will store zap output files.
- `--retain_zaps_on_completion` or `-r`: Retain zap files after completing a task.
- `--help` or `-h`: Show help information.
- `--version` or `-v`: Show the version of the agent.

### Running the Agent

To start the agent, run the following:
Expand Down
26 changes: 13 additions & 13 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,55 +46,55 @@ func Execute() {
func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cipherswarmagent.yaml)")
rootCmd.PersistentFlags().BoolVar(&enableDebug, "debug", false, "Enable debug mode")
rootCmd.PersistentFlags().BoolVarP(&enableDebug, "debug", "d", false, "Enable debug mode")
err := viper.BindPFlag("debug", rootCmd.PersistentFlags().Lookup("debug"))
cobra.CheckErr(err)

rootCmd.PersistentFlags().String("api_token", "", "API token for the CipherSwarm server")
rootCmd.PersistentFlags().StringP("api_token", "a", "", "API token for the CipherSwarm server")
err = viper.BindPFlag("api_token", rootCmd.PersistentFlags().Lookup("api_token"))
cobra.CheckErr(err)

rootCmd.PersistentFlags().String("api_url", "", "URL of the CipherSwarm server")
rootCmd.PersistentFlags().StringP("api_url", "u", "", "URL of the CipherSwarm server")
err = viper.BindPFlag("api_url", rootCmd.PersistentFlags().Lookup("api_url"))
cobra.CheckErr(err)

rootCmd.PersistentFlags().String("data_path", "", "Path to the directory where the agent will store data")
rootCmd.PersistentFlags().StringP("data_path", "p", "", "Path to the directory where the agent will store data")
err = viper.BindPFlag("data_path", rootCmd.PersistentFlags().Lookup("data_path"))
cobra.CheckErr(err)

rootCmd.PersistentFlags().Int("gpu_temp_threshold", 80, "Temperature threshold for the GPU in degrees Celsius")
rootCmd.PersistentFlags().IntP("gpu_temp_threshold", "g", 80, "Temperature threshold for the GPU in degrees Celsius")
err = viper.BindPFlag("gpu_temp_threshold", rootCmd.PersistentFlags().Lookup("gpu_temp_threshold"))
cobra.CheckErr(err)

rootCmd.PersistentFlags().Bool("always_use_native_hashcat", false, "Force using the native hashcat binary")
rootCmd.PersistentFlags().BoolP("always_use_native_hashcat", "n", false, "Force using the native hashcat binary")
err = viper.BindPFlag("always_use_native_hashcat", rootCmd.PersistentFlags().Lookup("always_use_native_hashcat"))
cobra.CheckErr(err)

rootCmd.PersistentFlags().Duration("sleep_on_failure", 60*time.Second, "Duration of sleep after a task failure")
rootCmd.PersistentFlags().DurationP("sleep_on_failure", "s", 60*time.Second, "Duration of sleep after a task failure")
err = viper.BindPFlag("sleep_on_failure", rootCmd.PersistentFlags().Lookup("sleep_on_failure"))
cobra.CheckErr(err)

rootCmd.PersistentFlags().String("files_path", "", "Path to the directory where the agent will store task files")
rootCmd.PersistentFlags().StringP("files_path", "f", "", "Path to the directory where the agent will store task files")
err = viper.BindPFlag("files_path", rootCmd.PersistentFlags().Lookup("files_path"))
cobra.CheckErr(err)

rootCmd.PersistentFlags().Bool("extra_debugging", false, "Enable additional debugging information")
rootCmd.PersistentFlags().BoolP("extra_debugging", "e", false, "Enable additional debugging information")
err = viper.BindPFlag("extra_debugging", rootCmd.PersistentFlags().Lookup("extra_debugging"))
cobra.CheckErr(err)

rootCmd.PersistentFlags().Int("status_timer", 3, "Interval in seconds for sending status updates to the server")
rootCmd.PersistentFlags().IntP("status_timer", "t", 3, "Interval in seconds for sending status updates to the server")
err = viper.BindPFlag("status_timer", rootCmd.PersistentFlags().Lookup("status_timer"))
cobra.CheckErr(err)

rootCmd.PersistentFlags().Bool("write_zaps_to_file", false, "Write zap output to a file in the zaps directory")
rootCmd.PersistentFlags().BoolP("write_zaps_to_file", "w", false, "Write zap output to a file in the zaps directory")
err = viper.BindPFlag("write_zaps_to_file", rootCmd.PersistentFlags().Lookup("write_zaps_to_file"))
cobra.CheckErr(err)

rootCmd.PersistentFlags().String("zap_path", "", "Path to the directory where the agent will store zap output files")
rootCmd.PersistentFlags().StringP("zap_path", "z", "", "Path to the directory where the agent will store zap output files")
err = viper.BindPFlag("zap_path", rootCmd.PersistentFlags().Lookup("zap_path"))
cobra.CheckErr(err)

rootCmd.PersistentFlags().Bool("retain_zaps_on_completion", false, "Retain zap files after completing a task")
rootCmd.PersistentFlags().BoolP("retain_zaps_on_completion", "r", false, "Retain zap files after completing a task")
err = viper.BindPFlag("retain_zaps_on_completion", rootCmd.PersistentFlags().Lookup("retain_zaps_on_completion"))
cobra.CheckErr(err)

Expand Down

0 comments on commit 42a48fa

Please sign in to comment.