Skip to content

Commit a7387ed

Browse files
authored
cmd: support using integer for duration flags (#1796)
1 parent 6685ed9 commit a7387ed

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

cmd/flags.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"os"
2121
"path"
2222
"runtime"
23+
"strconv"
2324
"time"
2425

2526
"github.com/urfave/cli/v2"
@@ -120,9 +121,10 @@ func clientFlags() []cli.Flag {
120121
Name: "writeback",
121122
Usage: "upload objects in background",
122123
},
123-
&cli.DurationFlag{
124+
&cli.StringFlag{
124125
Name: "upload-delay",
125-
Usage: "delayed duration for uploading objects (\"s\", \"m\", \"h\")",
126+
Value: "0",
127+
Usage: "delayed duration (in seconds) for uploading objects",
126128
},
127129
&cli.StringFlag{
128130
Name: "cache-dir",
@@ -143,15 +145,15 @@ func clientFlags() []cli.Flag {
143145
Name: "cache-partial-only",
144146
Usage: "cache only random/small read",
145147
},
146-
&cli.DurationFlag{
148+
&cli.StringFlag{
147149
Name: "backup-meta",
148-
Value: time.Hour,
149-
Usage: "interval to automatically backup metadata in the object storage (0 means disable backup)",
150+
Value: "3600",
151+
Usage: "interval (in seconds) to automatically backup metadata in the object storage (0 means disable backup)",
150152
},
151-
&cli.DurationFlag{
153+
&cli.StringFlag{
152154
Name: "heartbeat",
153-
Value: 12 * time.Second,
154-
Usage: "interval to send heartbeat; it's recommended that all clients use the same heartbeat value",
155+
Value: "12",
156+
Usage: "interval (in seconds) to send heartbeat; it's recommended that all clients use the same heartbeat value",
155157
},
156158
&cli.BoolFlag{
157159
Name: "read-only",
@@ -219,3 +221,13 @@ func expandFlags(compoundFlags [][]cli.Flag) []cli.Flag {
219221
}
220222
return flags
221223
}
224+
225+
func duration(s string) time.Duration {
226+
if v, err := strconv.ParseInt(s, 10, 64); err == nil {
227+
return time.Second * time.Duration(v)
228+
}
229+
if v, err := time.ParseDuration(s); err == nil {
230+
return v
231+
}
232+
return 0
233+
}

cmd/mount.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func getVfsConf(c *cli.Context, metaConf *meta.Config, format *meta.Format, chun
232232
Format: format,
233233
Version: version.Version(),
234234
Chunk: chunkConf,
235-
BackupMeta: c.Duration("backup-meta"),
235+
BackupMeta: duration(c.String("backup-meta")),
236236
}
237237
}
238238

@@ -272,7 +272,7 @@ func getMetaConf(c *cli.Context, mp string, readOnly bool) *meta.Config {
272272
ReadOnly: readOnly,
273273
NoBGJob: c.Bool("no-bgjob"),
274274
OpenCache: time.Duration(c.Float64("open-cache") * 1e9),
275-
Heartbeat: c.Duration("heartbeat"),
275+
Heartbeat: duration(c.String("heartbeat")),
276276
MountPoint: mp,
277277
Subdir: c.String("subdir"),
278278
}
@@ -355,7 +355,7 @@ func mount(c *cli.Context) error {
355355
}
356356

357357
chunkConf := getChunkConf(c, format)
358-
chunkConf.UploadDelay = c.Duration("upload-delay")
358+
chunkConf.UploadDelay = duration(c.String("upload-delay"))
359359

360360
blob, store := newStore(format, chunkConf, registerer)
361361
registerMetaMsg(metaCli, store, chunkConf)

0 commit comments

Comments
 (0)