2023-07-19 13:56:43 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/thegeeklab/url-parser/config"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// QueryFlags defines flags for query subcommand.
|
2023-07-19 18:39:30 +00:00
|
|
|
func QueryFlags(cfg *config.Config) []cli.Flag {
|
2023-07-19 13:56:43 +00:00
|
|
|
return []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "query-field",
|
|
|
|
Usage: "filter parsed query string by field name",
|
|
|
|
EnvVars: []string{"URL_PARSER_QUERY_FIELD"},
|
2023-07-19 18:39:30 +00:00
|
|
|
Destination: &cfg.QueryField,
|
2023-07-19 13:56:43 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Query prints out the query part from url.
|
2023-07-19 18:39:30 +00:00
|
|
|
func Query(cfg *config.Config) cli.ActionFunc {
|
2024-02-12 08:09:30 +00:00
|
|
|
return func(_ *cli.Context) error {
|
2024-11-05 13:35:26 +00:00
|
|
|
parts := NewURLParser(cfg.URL, cfg.QueryField, cfg.QuerySplit).parse()
|
2023-07-19 13:56:43 +00:00
|
|
|
|
2024-11-05 13:35:26 +00:00
|
|
|
if parts.Query != "" {
|
|
|
|
fmt.Println(parts.Query)
|
2023-07-19 13:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|