mirror of
https://github.com/aykhans/dodo.git
synced 2025-04-16 09:53:12 +00:00
✨ add yes flag to CLIConfigReader
This commit is contained in:
parent
75ada96d35
commit
ff1df870aa
@ -35,6 +35,7 @@ type RequestConfig struct {
|
||||
Cookies map[string]string
|
||||
Proxies []Proxy
|
||||
Body string
|
||||
Yes bool
|
||||
}
|
||||
|
||||
func (config *RequestConfig) Print() {
|
||||
@ -152,6 +153,7 @@ func (config *JSONConfig) MergeConfigs(newConfig *JSONConfig) {
|
||||
|
||||
type CLIConfig struct {
|
||||
Config
|
||||
Yes bool `json:"yes" validate:"omitempty"`
|
||||
ConfigFile string `validation_name:"config-file" validate:"omitempty,filepath"`
|
||||
}
|
||||
|
||||
|
19
main.go
19
main.go
@ -68,7 +68,7 @@ func main() {
|
||||
if err != nil {
|
||||
utils.PrintErrAndExit(err)
|
||||
}
|
||||
dodoConf := &config.RequestConfig{
|
||||
requestConf := &config.RequestConfig{
|
||||
Method: conf.Method,
|
||||
URL: parsedURL,
|
||||
Timeout: time.Duration(conf.Timeout) * time.Millisecond,
|
||||
@ -79,13 +79,16 @@ func main() {
|
||||
Cookies: jsonConf.Cookies,
|
||||
Proxies: jsonConf.Proxies,
|
||||
Body: jsonConf.Body,
|
||||
Yes: cliConf.Yes,
|
||||
}
|
||||
dodoConf.Print()
|
||||
response := readers.CLIYesOrNoReader("Do you want to continue?", true)
|
||||
if response {
|
||||
utils.PrintlnC(utils.Colors.Green, "Starting Dodo\n")
|
||||
} else {
|
||||
utils.PrintAndExit("Exiting...")
|
||||
requestConf.Print()
|
||||
if !cliConf.Yes {
|
||||
response := readers.CLIYesOrNoReader("Do you want to continue?", true)
|
||||
if response {
|
||||
utils.PrintlnC(utils.Colors.Green, "Starting Dodo\n")
|
||||
} else {
|
||||
utils.PrintAndExit("Exiting...")
|
||||
}
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@ -96,7 +99,7 @@ func main() {
|
||||
cancel()
|
||||
}()
|
||||
|
||||
responses, err := requests.Run(ctx, dodoConf)
|
||||
responses, err := requests.Run(ctx, requestConf)
|
||||
if err != nil {
|
||||
if customerrors.Is(err, customerrors.ErrInterrupt) {
|
||||
utils.PrintlnC(utils.Colors.Yellow, err.Error())
|
||||
|
@ -14,6 +14,7 @@ func CLIConfigReader() (*config.CLIConfig, error) {
|
||||
var (
|
||||
returnNil = false
|
||||
cliConfig = &config.CLIConfig{}
|
||||
// y bool
|
||||
dodosCount int
|
||||
requestCount int
|
||||
timeout int
|
||||
@ -45,6 +46,7 @@ func CLIConfigReader() (*config.CLIConfig, error) {
|
||||
)
|
||||
|
||||
rootCmd.Flags().StringVarP(&cliConfig.ConfigFile, "config-file", "c", "", "Path to the config file")
|
||||
rootCmd.Flags().BoolVarP(&cliConfig.Yes, "yes", "y", false, "Answer yes to all questions")
|
||||
rootCmd.Flags().StringVarP(&cliConfig.Method, "method", "m", "", fmt.Sprintf("HTTP Method (default %s)", config.DefaultMethod))
|
||||
rootCmd.Flags().StringVarP(&cliConfig.URL, "url", "u", "", "URL for stress testing")
|
||||
rootCmd.Flags().IntVarP(&dodosCount, "dodos-count", "d", config.DefaultDodosCount, "Number of dodos(threads)")
|
||||
|
@ -110,6 +110,7 @@ func Run(ctx context.Context, requestConfig *config.RequestConfig) (Responses, e
|
||||
requestConfig.Timeout,
|
||||
requestConfig.Proxies,
|
||||
requestConfig.GetValidDodosCountForProxies(),
|
||||
requestConfig.Yes,
|
||||
requestConfig.URL,
|
||||
)
|
||||
if clientDoFunc == nil {
|
||||
@ -260,6 +261,7 @@ func getClientDoFunc(
|
||||
timeout time.Duration,
|
||||
proxies []config.Proxy,
|
||||
dodosCount int,
|
||||
yes bool,
|
||||
URL *url.URL,
|
||||
) ClientDoFunc {
|
||||
isTLS := URL.Scheme == "https"
|
||||
@ -276,7 +278,7 @@ func getClientDoFunc(
|
||||
if activeProxyClientsCount == 0 {
|
||||
yesOrNoDefault = false
|
||||
yesOrNoMessage = utils.Colored(
|
||||
utils.Colors.Red,
|
||||
utils.Colors.Yellow,
|
||||
"No active proxies found. Do you want to continue?",
|
||||
)
|
||||
} else {
|
||||
@ -288,10 +290,11 @@ func getClientDoFunc(
|
||||
),
|
||||
)
|
||||
}
|
||||
fmt.Println()
|
||||
proceed := readers.CLIYesOrNoReader(yesOrNoMessage, yesOrNoDefault)
|
||||
if !proceed {
|
||||
utils.PrintAndExit("Exiting...")
|
||||
if !yes {
|
||||
response := readers.CLIYesOrNoReader("\n" + yesOrNoMessage, yesOrNoDefault)
|
||||
if !response {
|
||||
utils.PrintAndExit("Exiting...")
|
||||
}
|
||||
}
|
||||
fmt.Println()
|
||||
if activeProxyClientsCount == 0 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user