From 5b9b12b27205751c6bac261dc51e8b233b0d8170 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Thu, 17 Oct 2024 12:08:55 +1100 Subject: [PATCH] feat(cli): lotus chain head --height to print epoch number A simpler version of what's currently possible with: lotus chain list --format '' --count 1 --- cli/chain.go | 14 ++++++++++++-- documentation/en/cli-lotus.md | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cli/chain.go b/cli/chain.go index f941061d5d9..e04a715ac1e 100644 --- a/cli/chain.go +++ b/cli/chain.go @@ -72,6 +72,12 @@ var ChainCmd = &cli.Command{ var ChainHeadCmd = &cli.Command{ Name: "head", Usage: "Print chain head", + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "height", + Usage: "print just the epoch number of the chain head", + }, + }, Action: func(cctx *cli.Context) error { afmt := NewAppFmt(cctx.App) @@ -87,8 +93,12 @@ var ChainHeadCmd = &cli.Command{ return err } - for _, c := range head.Cids() { - afmt.Println(c) + if cctx.Bool("height") { + afmt.Println(head.Height()) + } else { + for _, c := range head.Cids() { + afmt.Println(c) + } } return nil }, diff --git a/documentation/en/cli-lotus.md b/documentation/en/cli-lotus.md index 7ec4f78a930..02950a2ba56 100644 --- a/documentation/en/cli-lotus.md +++ b/documentation/en/cli-lotus.md @@ -1616,6 +1616,7 @@ USAGE: lotus chain head [command options] [arguments...] OPTIONS: + --height print just the epoch number of the chain head (default: false) --help, -h show help ```