mirror of
https://codeberg.org/scip/ts.git
synced 2026-08-25 07:14:19 +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)
|
||||
|
||||
@@ -21,6 +21,8 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"codeberg.org/scip/ts/pkg/runexpr"
|
||||
)
|
||||
|
||||
func Die(format string, err error) int {
|
||||
@@ -36,6 +38,12 @@ func Main(output io.Writer) int {
|
||||
return Die("failed to initialize", err)
|
||||
}
|
||||
|
||||
if conf.Expr != "" {
|
||||
runexpr.RunExpr(conf.Expr)
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
tp := NewTP(conf)
|
||||
|
||||
if err := tp.ProcessTimestamps(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user