mirror of
https://github.com/guggero/chantools.git
synced 2026-08-13 12:33:34 +02:00
cmd/chantools: make results dir configurable
This commit is contained in:
parent
0b904f2135
commit
3402af3a42
11 changed files with 25 additions and 19 deletions
|
|
@ -108,7 +108,7 @@ chantools fakechanbackup --from_channel_graph lncli_describegraph.json \
|
|||
"LN channel graph in the JSON format that the "+
|
||||
"'lncli describegraph' returns",
|
||||
)
|
||||
multiFileName := fmt.Sprintf("results/fake-%s.backup",
|
||||
multiFileName := fmt.Sprintf("%s/fake-%s.backup", ResultsDir,
|
||||
time.Now().Format("2006-01-02-15-04-05"))
|
||||
cc.cmd.Flags().StringVar(
|
||||
&cc.MultiFile, "multi_file", multiFileName, "the fake channel "+
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ func filterChannelBackup(multiFile *chanbackup.MultiFile, ring keychain.KeyRing,
|
|||
}
|
||||
multi.StaticBackups = keep
|
||||
|
||||
fileName := fmt.Sprintf("results/backup-filtered-%s.backup",
|
||||
fileName := fmt.Sprintf("%s/backup-filtered-%s.backup", ResultsDir,
|
||||
time.Now().Format("2006-01-02-15-04-05"))
|
||||
log.Infof("Writing result to %s", fileName)
|
||||
f, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ func fixOldChannelBackup(multiFile *chanbackup.MultiFile,
|
|||
}
|
||||
|
||||
log.Infof("Fixed shachain root of %d channels.", fixedChannels)
|
||||
fileName := fmt.Sprintf("results/backup-fixed-%s.backup",
|
||||
fileName := fmt.Sprintf("%s/backup-fixed-%s.backup", ResultsDir,
|
||||
time.Now().Format("2006-01-02-15-04-05"))
|
||||
log.Infof("Writing result to %s", fileName)
|
||||
f, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
|
|
|
|||
|
|
@ -230,7 +230,7 @@ func forceCloseChannels(apiURL string, extendedKey *hdkeychain.ExtendedKey,
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fileName := fmt.Sprintf("results/forceclose-%s.json",
|
||||
fileName := fmt.Sprintf("%s/forceclose-%s.json", ResultsDir,
|
||||
time.Now().Format("2006-01-02-15-04-05"))
|
||||
log.Infof("Writing result to %s", fileName)
|
||||
return os.WriteFile(fileName, summaryBytes, 0644)
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ func (c *genImportScriptCommand) Execute(_ *cobra.Command, _ []string) error {
|
|||
|
||||
writer := os.Stdout
|
||||
if !c.Stdout {
|
||||
fileName := fmt.Sprintf("results/genimportscript-%s.txt",
|
||||
fileName := fmt.Sprintf("%s/genimportscript-%s.txt", ResultsDir,
|
||||
time.Now().Format("2006-01-02-15-04-05"))
|
||||
log.Infof("Writing import script with format '%s' to %s",
|
||||
c.Format, fileName)
|
||||
|
|
|
|||
|
|
@ -322,7 +322,7 @@ outer:
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fileName := fmt.Sprintf("results/rescueclosed-%s.json",
|
||||
fileName := fmt.Sprintf("%s/rescueclosed-%s.json", ResultsDir,
|
||||
time.Now().Format("2006-01-02-15-04-05"))
|
||||
log.Infof("Writing result to %s", fileName)
|
||||
return os.WriteFile(fileName, summaryBytes, 0644)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
|
@ -47,10 +48,11 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
Testnet bool
|
||||
Regtest bool
|
||||
Signet bool
|
||||
NoLogFile bool
|
||||
Testnet bool
|
||||
Regtest bool
|
||||
Signet bool
|
||||
NoLogFile bool
|
||||
ResultsDir string
|
||||
|
||||
log btclog.Logger
|
||||
|
||||
|
|
@ -106,6 +108,10 @@ func main() {
|
|||
"will be created. This is useful for testing purposes "+
|
||||
"where we don't want to create a log file.",
|
||||
)
|
||||
rootCmd.PersistentFlags().StringVar(
|
||||
&ResultsDir, "resultsdir", "./results", "Directory where "+
|
||||
"results should be stored",
|
||||
)
|
||||
|
||||
rootCmd.AddCommand(
|
||||
newChanBackupCommand(),
|
||||
|
|
@ -351,7 +357,7 @@ func setupLogging() {
|
|||
MaxLogFiles: 3,
|
||||
MaxLogFileSize: 10,
|
||||
},
|
||||
"./results/chantools.log",
|
||||
filepath.Join(ResultsDir, "chantools.log"),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ func summarizeChannels(apiURL string,
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fileName := fmt.Sprintf("results/summary-%s.json",
|
||||
fileName := fmt.Sprintf("%s/summary-%s.json", ResultsDir,
|
||||
time.Now().Format("2006-01-02-15-04-05"))
|
||||
log.Infof("Writing result to %s", fileName)
|
||||
return os.WriteFile(fileName, summaryBytes, 0644)
|
||||
|
|
@ -129,7 +129,7 @@ func summarizeAncientChannels(apiURL string,
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fileName := fmt.Sprintf("results/summary-ancient-%s.json",
|
||||
fileName := fmt.Sprintf("%s/summary-ancient-%s.json", ResultsDir,
|
||||
time.Now().Format("2006-01-02-15-04-05"))
|
||||
log.Infof("Writing result to %s", fileName)
|
||||
return os.WriteFile(fileName, summaryBytes, 0644)
|
||||
|
|
|
|||
|
|
@ -206,8 +206,8 @@ func (c *triggerForceCloseCommand) Execute(_ *cobra.Command, _ []string) error {
|
|||
peersBytes := []byte(strings.Join(pubKeys, "\n"))
|
||||
outputsBytes := []byte(strings.Join(outputs, "\n"))
|
||||
|
||||
fileName := fmt.Sprintf("results/forceclose-peers-%s.txt",
|
||||
time.Now().Format("2006-01-02"))
|
||||
fileName := fmt.Sprintf("%s/forceclose-peers-%s.txt",
|
||||
ResultsDir, time.Now().Format("2006-01-02"))
|
||||
log.Infof("Writing peers to %s", fileName)
|
||||
err = os.WriteFile(fileName, peersBytes, 0644)
|
||||
if err != nil {
|
||||
|
|
@ -215,8 +215,8 @@ func (c *triggerForceCloseCommand) Execute(_ *cobra.Command, _ []string) error {
|
|||
err)
|
||||
}
|
||||
|
||||
fileName = fmt.Sprintf("results/forceclose-addresses-%s.txt",
|
||||
time.Now().Format("2006-01-02"))
|
||||
fileName = fmt.Sprintf("%s/forceclose-addresses-%s.txt",
|
||||
ResultsDir, time.Now().Format("2006-01-02"))
|
||||
log.Infof("Writing addresses to %s", fileName)
|
||||
return os.WriteFile(fileName, outputsBytes, 0644)
|
||||
|
||||
|
|
|
|||
|
|
@ -316,7 +316,7 @@ func (c *zombieRecoveryFindMatchesCommand) Execute(_ *cobra.Command,
|
|||
Node1: node1,
|
||||
}
|
||||
|
||||
folder := "results/match-" + node1
|
||||
folder := fmt.Sprintf("%s/match-%s", ResultsDir, node1)
|
||||
today := time.Now().Format("2006-01-02")
|
||||
for node2, match := range node1map {
|
||||
err = os.MkdirAll(folder, 0755)
|
||||
|
|
|
|||
|
|
@ -247,7 +247,7 @@ func (c *zombieRecoveryPrepareKeysCommand) Execute(_ *cobra.Command,
|
|||
return err
|
||||
}
|
||||
|
||||
fileName := fmt.Sprintf("results/preparedkeys-%s-%s.json",
|
||||
fileName := fmt.Sprintf("%s/preparedkeys-%s-%s.json", ResultsDir,
|
||||
time.Now().Format("2006-01-02"), pubKeyStr)
|
||||
log.Infof("Writing result to %s", fileName)
|
||||
return os.WriteFile(fileName, matchBytes, 0644)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue