2022-02-25 05:26:40 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func setTime(c *cli.Context) error {
|
|
|
|
// Ensure required arguments
|
|
|
|
if c.Args().Len() < 1 {
|
|
|
|
return cli.Exit("Command time requires one argument", 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Args().Get(0) == "now" {
|
2022-05-01 22:22:28 +00:00
|
|
|
return client.SetTime(c.Context, time.Now())
|
2022-02-25 05:26:40 +00:00
|
|
|
} else {
|
|
|
|
parsed, err := time.Parse(time.RFC3339, c.Args().Get(0))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-05-01 22:22:28 +00:00
|
|
|
return client.SetTime(c.Context, parsed)
|
2022-02-25 05:26:40 +00:00
|
|
|
}
|
|
|
|
}
|