@@ -19,6 +19,7 @@ import (
19
19
"github.com/pyroscope-io/pyroscope/pkg/build"
20
20
"github.com/pyroscope-io/pyroscope/pkg/config"
21
21
"github.com/pyroscope-io/pyroscope/pkg/convert"
22
+ "github.com/pyroscope-io/pyroscope/pkg/dbmanager"
22
23
"github.com/pyroscope-io/pyroscope/pkg/exec"
23
24
"github.com/pyroscope-io/pyroscope/pkg/server"
24
25
"github.com/pyroscope-io/pyroscope/pkg/storage"
@@ -33,6 +34,8 @@ import (
33
34
"github.com/peterbourgon/ff/v3/ffcli"
34
35
)
35
36
37
+ const timeFormat = "2006-01-02T15:04:05Z0700"
38
+
36
39
type arrayFlags []string
37
40
38
41
func (i * arrayFlags ) String () string {
@@ -44,6 +47,26 @@ func (i *arrayFlags) Set(value string) error {
44
47
return nil
45
48
}
46
49
50
+ type timeFlag time.Time
51
+
52
+ func (tf * timeFlag ) String () string {
53
+ v := time .Time (* tf )
54
+ return v .Format (timeFormat )
55
+ }
56
+
57
+ func (tf * timeFlag ) Set (value string ) error {
58
+ t2 , err := time .Parse (timeFormat , value )
59
+ if err != nil {
60
+ return err
61
+ }
62
+
63
+ t := (* time .Time )(tf )
64
+ b , _ := t2 .MarshalBinary ()
65
+ t .UnmarshalBinary (b )
66
+
67
+ return nil
68
+ }
69
+
47
70
// this is mostly reflection magic
48
71
func populateFlagSet (obj interface {}, flagSet * flag.FlagSet ) {
49
72
v := reflect .ValueOf (obj ).Elem ()
@@ -80,6 +103,10 @@ func populateFlagSet(obj interface{}, flagSet *flag.FlagSet) {
80
103
case reflect .TypeOf (true ):
81
104
val := fieldV .Addr ().Interface ().(* bool )
82
105
flagSet .BoolVar (val , nameVal , defaultValStr == "true" , descVal )
106
+ case reflect .TypeOf (time.Time {}):
107
+ valTime := fieldV .Addr ().Interface ().(* time.Time )
108
+ val := (* timeFlag )(valTime )
109
+ flagSet .Var (val , nameVal , descVal )
83
110
case reflect .TypeOf (time .Second ):
84
111
val := fieldV .Addr ().Interface ().(* time.Duration )
85
112
var defaultVal time.Duration
@@ -147,18 +174,20 @@ func printUsage(c *ffcli.Command) string {
147
174
148
175
func Start (cfg * config.Config ) error {
149
176
var (
150
- rootFlagSet = flag .NewFlagSet ("pyroscope" , flag .ExitOnError )
151
- agentFlagSet = flag .NewFlagSet ("pyroscope agent" , flag .ExitOnError )
152
- serverFlagSet = flag .NewFlagSet ("pyroscope server" , flag .ExitOnError )
153
- convertFlagSet = flag .NewFlagSet ("pyroscope convert" , flag .ExitOnError )
154
- execFlagSet = flag .NewFlagSet ("pyroscope exec" , flag .ExitOnError )
177
+ rootFlagSet = flag .NewFlagSet ("pyroscope" , flag .ExitOnError )
178
+ agentFlagSet = flag .NewFlagSet ("pyroscope agent" , flag .ExitOnError )
179
+ serverFlagSet = flag .NewFlagSet ("pyroscope server" , flag .ExitOnError )
180
+ convertFlagSet = flag .NewFlagSet ("pyroscope convert" , flag .ExitOnError )
181
+ execFlagSet = flag .NewFlagSet ("pyroscope exec" , flag .ExitOnError )
182
+ dbmanagerFlagSet = flag .NewFlagSet ("pyroscope dbmanager" , flag .ExitOnError )
155
183
)
156
184
157
185
populateFlagSet (cfg , rootFlagSet )
158
186
populateFlagSet (& cfg .Agent , agentFlagSet )
159
187
populateFlagSet (& cfg .Server , serverFlagSet )
160
188
populateFlagSet (& cfg .Convert , convertFlagSet )
161
189
populateFlagSet (& cfg .Exec , execFlagSet )
190
+ populateFlagSet (& cfg .DbManager , dbmanagerFlagSet )
162
191
163
192
options := []ff.Option {
164
193
ff .WithConfigFileParser (ffyaml .Parser ),
@@ -203,6 +232,15 @@ func Start(cfg *config.Config) error {
203
232
FlagSet : execFlagSet ,
204
233
}
205
234
235
+ dbmanagerCmd := & ffcli.Command {
236
+ UsageFunc : printUsage ,
237
+ Options : options ,
238
+ Name : "dbmanager" ,
239
+ ShortUsage : "pyroscope dbmanager [flags] <args>" ,
240
+ ShortHelp : "tools for managing database" ,
241
+ FlagSet : dbmanagerFlagSet ,
242
+ }
243
+
206
244
rootCmd := & ffcli.Command {
207
245
UsageFunc : printUsage ,
208
246
Options : options ,
@@ -214,6 +252,7 @@ func Start(cfg *config.Config) error {
214
252
// convertCmd,
215
253
serverCmd ,
216
254
execCmd ,
255
+ dbmanagerCmd ,
217
256
},
218
257
}
219
258
@@ -248,6 +287,9 @@ func Start(cfg *config.Config) error {
248
287
249
288
return exec .Cli (cfg , args )
250
289
}
290
+ dbmanagerCmd .Exec = func (_ context.Context , args []string ) error {
291
+ return dbmanager .Cli (cfg , args )
292
+ }
251
293
rootCmd .Exec = func (_ context.Context , args []string ) error {
252
294
if cfg .Version || len (args ) > 0 && args [0 ] == "version" {
253
295
fmt .Println (gradientBanner ())
0 commit comments