Skip to content

Commit

Permalink
feat(cli): lotus chain head --height to print epoch number
Browse files Browse the repository at this point in the history
A simpler version of what's currently possible with:

	lotus chain list --format '<height>' --count 1
  • Loading branch information
rvagg committed Oct 17, 2024
1 parent 50f72ed commit 5b9b12b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cli/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
},
Expand Down
1 change: 1 addition & 0 deletions documentation/en/cli-lotus.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down

0 comments on commit 5b9b12b

Please sign in to comment.