Simplify, add epochtime package

pull/184/head
Simon Let 3 years ago
parent 4383d2b30a
commit 7d87c38d03
  1. 9
      cmd/get-epochtime/main.go
  2. 3
      cmd/postcollect/main.go
  3. 14
      internal/epochtime/epochtime.go
  4. 18
      internal/epochtime/epochtime_test.go
  5. 5
      internal/records/records.go
  6. 28
      scripts/hooks.sh
  7. 27
      scripts/util.sh
  8. 12
      test/Dockefile_macoslike

@ -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())
}

@ -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 {

@ -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())
}

@ -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")
}
}

@ -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"

@ -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
}

@ -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
}

@ -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
Loading…
Cancel
Save