Improve dump command
This commit is contained in:
parent
3bb07c5854
commit
4b311bcd5d
@ -34,7 +34,7 @@ func executor(cmd string) {
|
|||||||
var status = 0
|
var status = 0
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
log.Error().Caller().Msgf("PANIC: %s", r)
|
log.Error().Caller(3).Msgf("PANIC: %s", r)
|
||||||
}
|
}
|
||||||
if _, ok := noHist[cmd]; !ok && status == 0 {
|
if _, ok := noHist[cmd]; !ok && status == 0 {
|
||||||
history = append(history, cmd)
|
history = append(history, cmd)
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -321,12 +322,23 @@ func cmdDump(br *ziggy.Bridge, args []string) error {
|
|||||||
return errors.New("invalid target type")
|
return errors.New("invalid target type")
|
||||||
}
|
}
|
||||||
|
|
||||||
if js, err := json.Marshal(target); err != nil {
|
js, err := json.Marshal(target)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
return os.WriteFile(name+".json", js, 0o666)
|
|
||||||
}
|
}
|
||||||
|
name = name + ".json"
|
||||||
|
if err := os.WriteFile(name, js, 0o666); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// get current working directory
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
// we can't get the current working directory, but the file was written successfully (in theory).
|
||||||
|
// so just return nil without printing the path
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
log.Info().Msgf("dumped to: %s", filepath.Join(wd, name))
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// cmdLoad imports a target JSON object and attempts to apply it to an existing object
|
// cmdLoad imports a target JSON object and attempts to apply it to an existing object
|
||||||
|
Loading…
Reference in New Issue
Block a user