mirror of
https://codeberg.org/scip/ts.git
synced 2026-08-24 14:54:20 +02:00
add expr-lang.org support (use with -e)
This commit is contained in:
@@ -93,6 +93,7 @@ type Config struct {
|
||||
Examples bool `koanf:"examples"`
|
||||
Unit bool `koanf:"unit"`
|
||||
Format string `koanf:"format"`
|
||||
Expr string `koanf:"expr"`
|
||||
Args []string
|
||||
Output io.Writer
|
||||
Mode int
|
||||
@@ -121,8 +122,9 @@ func InitConfig(output io.Writer) (*Config, error) {
|
||||
flagset.BoolP("diff", "d", false, "diff two timestamps")
|
||||
flagset.BoolP("add", "a", false, "add two timestamps")
|
||||
flagset.BoolP("unit", "u", false, "add unit to diff outputs")
|
||||
flagset.BoolP("examples", "e", false, "show examples of supported inputs")
|
||||
flagset.BoolP("examples", "E", false, "show examples of supported inputs")
|
||||
flagset.StringP("format", "f", "", "format to print timestamps or diffs")
|
||||
flagset.StringP("expr", "e", "", "run expr program")
|
||||
|
||||
if err := flagset.Parse(os.Args[1:]); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse program arguments: %w", err)
|
||||
@@ -161,6 +163,11 @@ func InitConfig(output io.Writer) (*Config, error) {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if conf.Expr != "" {
|
||||
// ignore args etc
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
// args are timestamps
|
||||
if len(flagset.Args()) == 0 {
|
||||
return nil, errors.New("no timestamp argument[s] specified.\n" + Usage)
|
||||
|
||||
Reference in New Issue
Block a user