@@ -19,6 +19,7 @@ import (
1919 "github.com/yandex/perforator/perforator/internal/buildinfo/cobrabuildinfo"
2020 service "github.com/yandex/perforator/perforator/internal/web"
2121 "github.com/yandex/perforator/perforator/internal/xmetrics"
22+ "github.com/yandex/perforator/perforator/pkg/validateconfig"
2223 "github.com/yandex/perforator/perforator/pkg/xlog"
2324)
2425
@@ -38,35 +39,23 @@ var (
3839 logLevel string
3940)
4041
41- var (
42- storageConfigForValidationPath string
43-
44- storageValidateConfigCmd = & cobra.Command {
45- Use : "validate-config" ,
46- Short : "Validate storage config" ,
47- Args : cobra .NoArgs ,
48- Run : func (cmd * cobra.Command , args []string ) {
49- config , err := service .ParseConfig (storageConfigForValidationPath )
50- if err != nil {
51- fmt .Fprintf (os .Stderr , "Invalid config: %v\n " , err )
52- os .Exit (1 )
53- }
54- fmt .Printf ("%#v\n " , config )
55- },
56- }
57- )
58-
5942func init () {
6043 rootCmd .Flags ().StringVarP (& configPath , "config" , "c" , "" , "path to web service config" )
6144 rootCmd .Flags ().StringVarP (& logLevel , "log-level" , "l" , "info" , "log level (must be one of `debug`, `info`, `warn`, `error`)" )
6245
6346 cobrabuildinfo .Init (rootCmd )
6447
6548 rootCmd .MarkFlagsOneRequired ("config" )
66- rootCmd .AddCommand (storageValidateConfigCmd )
6749
68- storageValidateConfigCmd .Flags ().StringVarP (& storageConfigForValidationPath , "config" , "c" , "" , "path to web service config" )
69- storageValidateConfigCmd .MarkFlagsOneRequired ("config" )
50+ rootCmd .AddCommand (validateconfig .NewValidateConfigCmd (
51+ "web service" ,
52+ validateconfig .ValidateConfigFunc (
53+ func (configPath string ) error {
54+ _ , err := service .ParseConfig (configPath )
55+ return err
56+ },
57+ ),
58+ ))
7059}
7160
7261func main () {
0 commit comments