Skip to content

Commit

Permalink
refactor: return commands with functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tbruyelle committed Mar 27, 2024
1 parent 502efbc commit 242dc4b
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func main() {
rootCmd := &ffcli.Command{
ShortUsage: "govbox <subcommand> <path>",
ShortHelp: "Set of commands for GovGen proposals.",
Subcommands: []*ffcli.Command{tallyCmd, accountsCmd, genesisCmd, autoStakingCmd, distributionCmd},
Subcommands: []*ffcli.Command{tallyCmd(), accountsCmd(), genesisCmd(), autoStakingCmd(), distributionCmd()},
Exec: func(ctx context.Context, args []string) error {
return flag.ErrHelp
},
Expand All @@ -27,8 +27,8 @@ func main() {
}
}

var (
tallyCmd = &ffcli.Command{
func tallyCmd() *ffcli.Command {
return &ffcli.Command{
Name: "tally",
ShortUsage: "govbox tally <path>",
ShortHelp: "Print the comparison between the tally result and the tally computed from <path>",
Expand All @@ -54,8 +54,10 @@ var (
return nil
},
}
}

accountsCmd = &ffcli.Command{
func accountsCmd() *ffcli.Command {
return &ffcli.Command{
Name: "accounts",
ShortUsage: "govbox accounts <path>",
ShortHelp: "Consolidate the data in <path> into a single file <path>/accounts.json",
Expand Down Expand Up @@ -102,8 +104,10 @@ var (
return nil
},
}
}

genesisCmd = &ffcli.Command{
func genesisCmd() *ffcli.Command {
return &ffcli.Command{
Name: "genesis",
ShortUsage: "govbox genesis <path>",
ShortHelp: "Convert <path>/accounts.json to <path>/bank.genesis",
Expand All @@ -130,8 +134,10 @@ The command must be run once <path>/accounts.json is generated by the
return nil
},
}
}

autoStakingCmd = &ffcli.Command{
func autoStakingCmd() *ffcli.Command {
return &ffcli.Command{
Name: "autostaking",
ShortUsage: "govbox autostaking <path>",
ShortHelp: "Experimental command to evaluate auto-staking algorithms",
Expand All @@ -144,16 +150,23 @@ The command must be run once <path>/accounts.json is generated by the
return autoStaking(filepath.Join(datapath, "genesis.json"))
},
}
}

distributionCmd = &ffcli.Command{
func distributionCmd() *ffcli.Command {
fs := flag.NewFlagSet("distribution", flag.ContinueOnError)
chartMode := fs.Bool("chart", false, "Outputs a chart instead of Markdown tables")

cmd := &ffcli.Command{
Name: "distribution",
ShortUsage: "govbox distribution <path>",
ShortHelp: "Convert <path>/accounts.json into <path>/airdrop.json",
LongHelp: `Generate the ATONE distribution described in GovGen PROP 001`,
FlagSet: fs,
Exec: func(ctx context.Context, args []string) error {
if len(args) == 0 {
return flag.ErrHelp
}
fs.Parse(args)
var (
datapath = args[0]
accountsFile = filepath.Join(datapath, "accounts.json")
Expand All @@ -174,8 +187,8 @@ The command must be run once <path>/accounts.json is generated by the
if err := os.WriteFile(airdropFile, bz, 0o666); err != nil {
return err
}
printAirdropStats(airdrop)
return nil
return printAirdropStats(airdrop, *chartMode)
},
}
)
return cmd
}

0 comments on commit 242dc4b

Please sign in to comment.