refactor(blockchain): centralise chain example labels

Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
Virgil 2026-04-04 10:42:25 +00:00
parent a0e20f0c49
commit fa7b674c4f
4 changed files with 10 additions and 7 deletions

View file

@ -32,6 +32,7 @@ const chainExplorerExample = chainExplorerCommandPath + " --data-dir ~/.lethean/
const chainSyncExample = chainSyncCommandPath + "\n" +
chainSyncCommandPath + " --daemon\n" +
chainSyncCommandPath + " --stop"
const chainCommandExample = chainExplorerExample + "\n" + chainSyncExample
// AddChainCommands registers the `chain` command group on a Cobra root.
//
@ -54,7 +55,7 @@ func AddChainCommands(root *cobra.Command) {
Use: ChainCommandName,
Short: "Manage the Lethean blockchain node",
Long: "Manage the Lethean blockchain node: sync and explore.",
Example: chainExplorerExample + "\n" + chainSyncExample,
Example: chainCommandExample,
Args: cobra.NoArgs,
}

View file

@ -22,7 +22,7 @@ func TestAddChainCommands_Good_RegistersParent(t *testing.T) {
assert.Equal(t, ChainCommandName, chainCmd.Name())
assert.Equal(t, "Manage the Lethean blockchain node", chainCmd.Short)
assert.Equal(t, "Manage the Lethean blockchain node: sync and explore.", chainCmd.Long)
assert.Equal(t, chainExplorerExample+"\n"+chainSyncExample, chainCmd.Example)
assert.Equal(t, chainCommandExample, chainCmd.Example)
}
func TestAddChainCommands_Good_HasSubcommands(t *testing.T) {

View file

@ -23,6 +23,8 @@ import (
"github.com/spf13/cobra"
)
const chainSyncDisplayName = ChainCommandName + " " + chainSyncCommandName
// newChainSyncCommand builds the `chain sync` command family.
//
// Example:
@ -82,9 +84,9 @@ func runChainSyncForeground(dataDir, seed string, testnet bool) error {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer cancel()
log.Println("Starting headless P2P synchronisation...")
log.Printf("Starting %s in foreground...", chainSyncDisplayName)
runChainSyncLoop(ctx, blockchain, &chainConfig, hardForks, resolvedSeed)
log.Println("Sync stopped.")
log.Printf("%s stopped.", chainSyncDisplayName)
return nil
}
@ -123,7 +125,7 @@ func runChainSyncDaemon(dataDir, seed string, testnet bool) error {
defer cancel()
syncDaemon.SetReady(true)
log.Println("Sync daemon started.")
log.Printf("%s daemon started.", chainSyncDisplayName)
var wg sync.WaitGroup
wg.Add(1)
@ -153,6 +155,6 @@ func stopChainSyncDaemon(dataDir string) error {
return coreerr.E("stopChainSyncDaemon", fmt.Sprintf("signal process %d", pid), err)
}
log.Printf("Sent SIGTERM to sync daemon (PID %d)", pid)
log.Printf("Sent SIGTERM to %s daemon (PID %d)", chainSyncDisplayName, pid)
return nil
}

View file

@ -36,7 +36,7 @@ func runChainSyncLoop(ctx context.Context, blockchain *chain.Chain, chainConfig
}
if err := runChainSyncOnce(ctx, blockchain, chainConfig, opts, seed); err != nil {
log.Printf("sync: %v (retrying in 10s)", err)
log.Printf("%s: %v (retrying in 10s)", chainSyncDisplayName, err)
select {
case <-ctx.Done():
return