mirror of
https://github.com/aykhans/dodo.git
synced 2025-04-20 11:11:26 +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
|
Cookies map[string]string
|
||||||
Proxies []Proxy
|
Proxies []Proxy
|
||||||
Body string
|
Body string
|
||||||
|
Yes bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *RequestConfig) Print() {
|
func (config *RequestConfig) Print() {
|
||||||
@ -152,6 +153,7 @@ func (config *JSONConfig) MergeConfigs(newConfig *JSONConfig) {
|
|||||||
|
|
||||||
type CLIConfig struct {
|
type CLIConfig struct {
|
||||||
Config
|
Config
|
||||||
|
Yes bool `json:"yes" validate:"omitempty"`
|
||||||
ConfigFile string `validation_name:"config-file" validate:"omitempty,filepath"`
|
ConfigFile string `validation_name:"config-file" validate:"omitempty,filepath"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
9
main.go
9
main.go
@ -68,7 +68,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
utils.PrintErrAndExit(err)
|
utils.PrintErrAndExit(err)
|
||||||
}
|
}
|
||||||
dodoConf := &config.RequestConfig{
|
requestConf := &config.RequestConfig{
|
||||||
Method: conf.Method,
|
Method: conf.Method,
|
||||||
URL: parsedURL,
|
URL: parsedURL,
|
||||||
Timeout: time.Duration(conf.Timeout) * time.Millisecond,
|
Timeout: time.Duration(conf.Timeout) * time.Millisecond,
|
||||||
@ -79,14 +79,17 @@ func main() {
|
|||||||
Cookies: jsonConf.Cookies,
|
Cookies: jsonConf.Cookies,
|
||||||
Proxies: jsonConf.Proxies,
|
Proxies: jsonConf.Proxies,
|
||||||
Body: jsonConf.Body,
|
Body: jsonConf.Body,
|
||||||
|
Yes: cliConf.Yes,
|
||||||
}
|
}
|
||||||
dodoConf.Print()
|
requestConf.Print()
|
||||||
|
if !cliConf.Yes {
|
||||||
response := readers.CLIYesOrNoReader("Do you want to continue?", true)
|
response := readers.CLIYesOrNoReader("Do you want to continue?", true)
|
||||||
if response {
|
if response {
|
||||||
utils.PrintlnC(utils.Colors.Green, "Starting Dodo\n")
|
utils.PrintlnC(utils.Colors.Green, "Starting Dodo\n")
|
||||||
} else {
|
} else {
|
||||||
utils.PrintAndExit("Exiting...")
|
utils.PrintAndExit("Exiting...")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
sigChan := make(chan os.Signal, 1)
|
sigChan := make(chan os.Signal, 1)
|
||||||
@ -96,7 +99,7 @@ func main() {
|
|||||||
cancel()
|
cancel()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
responses, err := requests.Run(ctx, dodoConf)
|
responses, err := requests.Run(ctx, requestConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if customerrors.Is(err, customerrors.ErrInterrupt) {
|
if customerrors.Is(err, customerrors.ErrInterrupt) {
|
||||||
utils.PrintlnC(utils.Colors.Yellow, err.Error())
|
utils.PrintlnC(utils.Colors.Yellow, err.Error())
|
||||||
|
@ -14,6 +14,7 @@ func CLIConfigReader() (*config.CLIConfig, error) {
|
|||||||
var (
|
var (
|
||||||
returnNil = false
|
returnNil = false
|
||||||
cliConfig = &config.CLIConfig{}
|
cliConfig = &config.CLIConfig{}
|
||||||
|
// y bool
|
||||||
dodosCount int
|
dodosCount int
|
||||||
requestCount int
|
requestCount int
|
||||||
timeout 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().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.Method, "method", "m", "", fmt.Sprintf("HTTP Method (default %s)", config.DefaultMethod))
|
||||||
rootCmd.Flags().StringVarP(&cliConfig.URL, "url", "u", "", "URL for stress testing")
|
rootCmd.Flags().StringVarP(&cliConfig.URL, "url", "u", "", "URL for stress testing")
|
||||||
rootCmd.Flags().IntVarP(&dodosCount, "dodos-count", "d", config.DefaultDodosCount, "Number of dodos(threads)")
|
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.Timeout,
|
||||||
requestConfig.Proxies,
|
requestConfig.Proxies,
|
||||||
requestConfig.GetValidDodosCountForProxies(),
|
requestConfig.GetValidDodosCountForProxies(),
|
||||||
|
requestConfig.Yes,
|
||||||
requestConfig.URL,
|
requestConfig.URL,
|
||||||
)
|
)
|
||||||
if clientDoFunc == nil {
|
if clientDoFunc == nil {
|
||||||
@ -260,6 +261,7 @@ func getClientDoFunc(
|
|||||||
timeout time.Duration,
|
timeout time.Duration,
|
||||||
proxies []config.Proxy,
|
proxies []config.Proxy,
|
||||||
dodosCount int,
|
dodosCount int,
|
||||||
|
yes bool,
|
||||||
URL *url.URL,
|
URL *url.URL,
|
||||||
) ClientDoFunc {
|
) ClientDoFunc {
|
||||||
isTLS := URL.Scheme == "https"
|
isTLS := URL.Scheme == "https"
|
||||||
@ -276,7 +278,7 @@ func getClientDoFunc(
|
|||||||
if activeProxyClientsCount == 0 {
|
if activeProxyClientsCount == 0 {
|
||||||
yesOrNoDefault = false
|
yesOrNoDefault = false
|
||||||
yesOrNoMessage = utils.Colored(
|
yesOrNoMessage = utils.Colored(
|
||||||
utils.Colors.Red,
|
utils.Colors.Yellow,
|
||||||
"No active proxies found. Do you want to continue?",
|
"No active proxies found. Do you want to continue?",
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
@ -288,11 +290,12 @@ func getClientDoFunc(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fmt.Println()
|
if !yes {
|
||||||
proceed := readers.CLIYesOrNoReader(yesOrNoMessage, yesOrNoDefault)
|
response := readers.CLIYesOrNoReader("\n" + yesOrNoMessage, yesOrNoDefault)
|
||||||
if !proceed {
|
if !response {
|
||||||
utils.PrintAndExit("Exiting...")
|
utils.PrintAndExit("Exiting...")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
if activeProxyClientsCount == 0 {
|
if activeProxyClientsCount == 0 {
|
||||||
client := &fasthttp.HostClient{
|
client := &fasthttp.HostClient{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user