diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go index 363b8284..4880bb52 100644 --- a/pkg/cmd/root.go +++ b/pkg/cmd/root.go @@ -61,8 +61,8 @@ func init() { ID: "server", Title: "HTTP Server", }) - rootCmd.PersistentFlags().StringVar(&constants.JR_SYSTEM_DIR, "system_dir", "", "JR system dir") - rootCmd.PersistentFlags().StringVar(&constants.JR_USER_DIR, "user_dir", "", "JR user dir") + rootCmd.PersistentFlags().StringVar(&constants.JR_SYSTEM_DIR, "jr_system_dir", "", "JR system dir") + rootCmd.PersistentFlags().StringVar(&constants.JR_USER_DIR, "jr_user_dir", "", "JR user dir") rootCmd.PersistentFlags().StringVar(&logLevel, "log_level", constants.DEFAULT_LOG_LEVEL, "HR Log Level") } diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index eccf1fa7..9d82daec 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -22,6 +22,7 @@ package cmd import ( "fmt" + "github.com/jrnd-io/jr/pkg/constants" "github.com/spf13/cobra" ) @@ -34,11 +35,13 @@ var versionCmd = &cobra.Command{ Use: "version", Short: "prints JR version number", Long: `prints JR version number`, - Run: func(cmd *cobra.Command, args []string) { - fmt.Printf("JR Version: %s\n", Version) - fmt.Printf("Built with: %s\n", GoVersion) - fmt.Printf(" by: %s\n", BuildUser) - fmt.Printf(" at: %s\n", BuildTime) + Run: func(_ *cobra.Command, _ []string) { + fmt.Printf("JR System Dir: %s\n", constants.JR_SYSTEM_DIR) + fmt.Printf("JR User Dir : %s\n", constants.JR_USER_DIR) + fmt.Printf("JR Version : %s\n", Version) + fmt.Printf("Built with : %s\n", GoVersion) + fmt.Printf("By : %s\n", BuildUser) + fmt.Printf("At : %s\n", BuildTime) }, } diff --git a/pkg/functions/functions.go b/pkg/functions/functions.go index be219d93..1a9a7c2f 100644 --- a/pkg/functions/functions.go +++ b/pkg/functions/functions.go @@ -167,6 +167,7 @@ var fmap = map[string]interface{}{ "future": Future, "past": Past, "recent": Recent, + "justpassed": Justpassed, "soon": Soon, "unix_time_stamp": UnixTimeStamp, diff --git a/pkg/functions/functionsDescription.go b/pkg/functions/functionsDescription.go index af192274..199d9d1c 100644 --- a/pkg/functions/functionsDescription.go +++ b/pkg/functions/functionsDescription.go @@ -654,6 +654,16 @@ var funcDesc = map[string]FunctionDescription{ Example: "jr template run --embedded '{{join \"hello,\" \"world\"}}'", Output: "hello,world", }, + "justpassed": { + Name: "justpassed", + Category: "time", + Description: "returns a date in the past not before the given milliseconds", + Parameters: "milliseconds int", + Localizable: false, + Return: "string", + Example: "jr template run --embedded '{{justpassed 15}}'", + Output: "2024-11-10 22:59:5", + }, "key": { Name: "key", Category: "utilities", diff --git a/pkg/functions/timeAndDates.go b/pkg/functions/timeAndDates.go index 7501d216..61f33f7c 100644 --- a/pkg/functions/timeAndDates.go +++ b/pkg/functions/timeAndDates.go @@ -110,6 +110,16 @@ func Recent(days int) string { return d.Format(time.DateOnly) } +// Justpassed returns a date in the past not before the given milliseconds +func Justpassed(milliseconds int64) string { + now := time.Now() + + duration := time.Duration(milliseconds) * time.Millisecond + pastTime := now.Add(-duration) + + return pastTime.Format(time.DateTime) +} + // Soon returns a date in the future not after the given days func Soon(days int) string { now := time.Now().UTC()