diff --git a/cmd/get-epochtime/main.go b/cmd/get-epochtime/main.go index e63c1533..2000414 100644 --- a/cmd/get-epochtime/main.go +++ b/cmd/get-epochtime/main.go @@ -2,16 +2,13 @@ package main import ( "fmt" - "time" + + "github.com/curusarn/resh/internal/epochtime" ) // Small utility to get epochtime in millisecond precision // Doesn't check arguments // Exits with status 1 on error func main() { - fmt.Printf("%s", timeToEpochTime(time.Now())) -} - -func timeToEpochTime(t time.Time) string { - return fmt.Sprintf("%.2f", float64(t.UnixMilli())/1000) + fmt.Printf("%s", epochtime.Now()) } diff --git a/cmd/postcollect/main.go b/cmd/postcollect/main.go index 041e72f..998e26b 100644 --- a/cmd/postcollect/main.go +++ b/cmd/postcollect/main.go @@ -7,6 +7,7 @@ import ( "github.com/curusarn/resh/internal/cfg" "github.com/curusarn/resh/internal/collect" + "github.com/curusarn/resh/internal/epochtime" "github.com/curusarn/resh/internal/logger" "github.com/curusarn/resh/internal/output" "github.com/curusarn/resh/internal/recordint" @@ -24,6 +25,8 @@ var commit string var development string func main() { + epochTime := epochtime.Now() + config, errCfg := cfg.New() logger, err := logger.New("postcollect", config.LogLevel, development) if err != nil { diff --git a/internal/epochtime/epochtime.go b/internal/epochtime/epochtime.go new file mode 100644 index 0000000..82d4dbc --- /dev/null +++ b/internal/epochtime/epochtime.go @@ -0,0 +1,14 @@ +package epochtime + +import ( + "fmt" + "time" +) + +func TimeToString(t time.Time) string { + return fmt.Sprintf("%.2f", float64(t.UnixMilli())/1000) +} + +func Now() string { + return TimeToString(time.Now()) +} diff --git a/internal/epochtime/epochtime_test.go b/internal/epochtime/epochtime_test.go new file mode 100644 index 0000000..596ab13 --- /dev/null +++ b/internal/epochtime/epochtime_test.go @@ -0,0 +1,18 @@ +package epochtime + +import ( + "strconv" + "testing" + "time" +) + +func TestConversion(t *testing.T) { + epochTime := "1672702332.64" + seconds, err := strconv.ParseFloat(epochTime, 64) + if err != nil { + t.Fatal("Test setup failed: Failed to convert constant") + } + if TimeToString(time.UnixMilli(int64(seconds*1000))) != epochTime { + t.Fatal("EpochTime changed during conversion") + } +} diff --git a/internal/records/records.go b/internal/records/records.go index a9972d2..699a50a 100644 --- a/internal/records/records.go +++ b/internal/records/records.go @@ -1,5 +1,10 @@ package records +// DEPRECATION NOTICE: This package should be removed in favor of: +// - record: public record definitions +// - recordint: internal record definitions +// - recutil: record-related utils + import ( "bufio" "os" diff --git a/scripts/hooks.sh b/scripts/hooks.sh index 3a4f6fe..6753d2e 100644 --- a/scripts/hooks.sh +++ b/scripts/hooks.sh @@ -63,7 +63,7 @@ __resh_precmd() { if [ -n "${__RESH_COLLECT}" ]; then if [ "$__RESH_VERSION" != "$(resh-postcollect -version)" ]; then # shellcheck source=shellrc.sh - source ~/.resh/shellrc + source ~/.resh/shellrc if [ "$__RESH_VERSION" != "$(resh-postcollect -version)" ]; then echo "RESH WARNING: You probably just updated RESH - PLEASE RESTART OR RELOAD THIS TERMINAL SESSION (resh version: $(resh-collect -version); resh version of this terminal session: ${__RESH_VERSION})" else @@ -71,7 +71,7 @@ __resh_precmd() { fi elif [ "$__RESH_REVISION" != "$(resh-postcollect -revision)" ]; then # shellcheck source=shellrc.sh - source ~/.resh/shellrc + source ~/.resh/shellrc if [ "$__RESH_REVISION" != "$(resh-postcollect -revision)" ]; then echo "RESH WARNING: You probably just updated RESH - PLEASE RESTART OR RELOAD THIS TERMINAL SESSION (resh revision: $(resh-collect -revision); resh revision of this terminal session: ${__RESH_REVISION})" fi @@ -90,3 +90,27 @@ __resh_precmd() { fi unset __RESH_COLLECT } + +__resh_session_init() { + if [ "$__RESH_VERSION" != "$(resh-session-init -version)" ]; then + # shellcheck source=shellrc.sh + source ~/.resh/shellrc + if [ "$__RESH_VERSION" != "$(resh-session-init -version)" ]; then + echo "RESH WARNING: You probably just updated RESH - PLEASE RESTART OR RELOAD THIS TERMINAL SESSION (resh version: $(resh-session-init -version); resh version of this terminal session: ${__RESH_VERSION})" + else + echo "RESH INFO: New RESH shellrc script was loaded - if you encounter any issues please restart this terminal session." + fi + elif [ "$__RESH_REVISION" != "$(resh-session-init -revision)" ]; then + # shellcheck source=shellrc.sh + source ~/.resh/shellrc + if [ "$__RESH_REVISION" != "$(resh-session-init -revision)" ]; then + echo "RESH WARNING: You probably just updated RESH - PLEASE RESTART OR RELOAD THIS TERMINAL SESSION (resh revision: $(resh-session-init -revision); resh revision of this terminal session: ${__RESH_REVISION})" + fi + fi + if [ "$__RESH_VERSION" = "$(resh-session-init -version)" ] && [ "$__RESH_REVISION" = "$(resh-session-init -revision)" ]; then + resh-session-init -requireVersion "$__RESH_VERSION" \ + -requireRevision "$__RESH_REVISION" \ + -sessionId "$__RESH_SESSION_ID" \ + -sessionPid "$__RESH_SESSION_PID" + fi +} \ No newline at end of file diff --git a/scripts/util.sh b/scripts/util.sh deleted file mode 100644 index a1f89c0..0000000 --- a/scripts/util.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/hint/sh - -# util.sh - resh utility functions - -__resh_session_init() { - if [ "$__RESH_VERSION" != "$(resh-session-init -version)" ]; then - # shellcheck source=shellrc.sh - source ~/.resh/shellrc - if [ "$__RESH_VERSION" != "$(resh-session-init -version)" ]; then - echo "RESH WARNING: You probably just updated RESH - PLEASE RESTART OR RELOAD THIS TERMINAL SESSION (resh version: $(resh-session-init -version); resh version of this terminal session: ${__RESH_VERSION})" - else - echo "RESH INFO: New RESH shellrc script was loaded - if you encounter any issues please restart this terminal session." - fi - elif [ "$__RESH_REVISION" != "$(resh-session-init -revision)" ]; then - # shellcheck source=shellrc.sh - source ~/.resh/shellrc - if [ "$__RESH_REVISION" != "$(resh-session-init -revision)" ]; then - echo "RESH WARNING: You probably just updated RESH - PLEASE RESTART OR RELOAD THIS TERMINAL SESSION (resh revision: $(resh-session-init -revision); resh revision of this terminal session: ${__RESH_REVISION})" - fi - fi - if [ "$__RESH_VERSION" = "$(resh-session-init -version)" ] && [ "$__RESH_REVISION" = "$(resh-session-init -revision)" ]; then - resh-session-init -requireVersion "$__RESH_VERSION" \ - -requireRevision "$__RESH_REVISION" \ - -sessionId "$__RESH_SESSION_ID" \ - -sessionPid "$__RESH_SESSION_PID" - fi -} diff --git a/test/Dockefile_macoslike b/test/Dockefile_macoslike deleted file mode 100644 index 6e8c524..0000000 --- a/test/Dockefile_macoslike +++ /dev/null @@ -1,12 +0,0 @@ -FROM debian:jessie - -RUN apt-get update && apt-get install -y wget tar gcc automake make bison flex curl vim makeinfo -RUN wget https://ftp.gnu.org/gnu/bash/bash-3.2.57.tar.gz && \ - tar -xvzf bash-3.2.57.tar.gz && \ - cd bash-3.2.57 && \ - ./configure && \ - make && \ - make install -RUN echo /usr/local/bin/bash >> /etc/shells && chsh -s /usr/local/bin/bash - -CMD bash