Skip to content

Commit

Permalink
Standardize cli flag format (#728)
Browse files Browse the repository at this point in the history
* cli flag format

* fix

* config init, e2e test

* remove deprecated

* pr review refactor

* pr review refactor

* pr refactor review

* Fixes (#6)

---------

Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com>
  • Loading branch information
sekulicd and altafan authored Jul 6, 2023
1 parent 0457471 commit bf3b384
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 185 deletions.
6 changes: 3 additions & 3 deletions cmd/tdex/changepassword.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
)

const (
curPwdFlagName = "current_password"
newPwdFlagName = "new_password"
curPwdFlagName = "current-password"
newPwdFlagName = "new-password"
)

var changepassword = cli.Command{
Expand All @@ -23,7 +23,7 @@ var changepassword = cli.Command{
Value: "",
},
&cli.StringFlag{
Name: "new_password",
Name: "new-password",
Usage: "the new password that replaces the old one",
Value: "",
},
Expand Down
22 changes: 14 additions & 8 deletions cmd/tdex/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"strconv"
"strings"

"github.com/btcsuite/btcd/btcutil"
"github.com/tdex-network/tdex-daemon/pkg/tdexdconnect"
Expand All @@ -31,6 +32,11 @@ var (
defaultMacaroonsPath = filepath.Join(daemonDatadir, "macaroons", "admin.macaroon")
defaultNoTLS = false

noMacaroonsFlagName = strings.Replace(noMacaroonsKey, "_", "-", -1)
macaroonsPathFlagName = strings.Replace(macaroonsPathKey, "_", "-", -1)
tlsCertPathFlagName = strings.Replace(tlsCertPathKey, "_", "-", -1)
noTlsFlagName = strings.Replace(noTlsKey, "_", "-", -1)

networkFlag = cli.StringFlag{
Name: "network, n",
Usage: "the network tdexd is running on: liquid or regtest",
Expand All @@ -44,25 +50,25 @@ var (
}

tlsCertFlag = cli.StringFlag{
Name: tlsCertPathKey,
Name: tlsCertPathFlagName,
Usage: "the path of the TLS certificate file to use",
Value: defaultTLSCertPath,
}

noTlsFlag = cli.BoolFlag{
Name: noTlsKey,
Name: noTlsFlagName,
Usage: "used to disable operator TLS certificate",
Value: defaultNoTLS,
}

noMacaroonsFlag = cli.BoolFlag{
Name: noMacaroonsKey,
Name: noMacaroonsFlagName,
Usage: "used to start the daemon without macaroon auth",
Value: defaultNoMacaroonsAuth,
}

macaroonsFlag = cli.StringFlag{
Name: macaroonsPathKey,
Name: macaroonsPathFlagName,
Usage: "the path of the macaroons file to use",
Value: defaultMacaroonsPath,
}
Expand Down Expand Up @@ -116,10 +122,10 @@ func configInitAction(c *cli.Context) error {
return setState(map[string]string{
"network": c.String("network"),
"rpcserver": c.String("rpcserver"),
"no_macaroons": c.String(noMacaroonsKey),
"no_tls": c.String(noTlsKey),
"tls_cert_path": cleanAndExpandPath(c.String(tlsCertPathKey)),
"macaroons_path": cleanAndExpandPath(c.String(macaroonsPathKey)),
noMacaroonsKey: c.String(noMacaroonsFlagName),
noTlsKey: c.String(noTlsFlagName),
tlsCertPathKey: cleanAndExpandPath(c.String(tlsCertPathFlagName)),
macaroonsPathKey: cleanAndExpandPath(c.String(macaroonsPathFlagName)),
})
}

Expand Down
21 changes: 5 additions & 16 deletions cmd/tdex/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ var (
Name: "fee",
Usage: "manage the fee account of the daemon's wallet",
Subcommands: []*cli.Command{
feeBalanceCmd, feeDepositCmd, feeListAddressesCmd, feeClaimCmd,
feeWithdrawCmd,
feeBalanceCmd, feeDepositCmd, feeListAddressesCmd, feeWithdrawCmd,
},
}

Expand All @@ -27,7 +26,7 @@ var (
Usage: "generate some address(es) to receive funds",
Flags: []cli.Flag{
&cli.UintFlag{
Name: "num_of_addresses",
Name: "num-of-addresses",
Usage: "the number of addresses to generate",
},
},
Expand All @@ -38,11 +37,6 @@ var (
Usage: "list all the derived deposit addresses of the fee account",
Action: feeListAddressesAction,
}
feeClaimCmd = &cli.Command{
Name: "claim",
Usage: "DEPRECATED: claim deposits for the fee account",
Action: feeClaimAction,
}
feeWithdrawCmd = &cli.Command{
Name: "withdraw",
Usage: "withdraw funds from fee account",
Expand All @@ -53,7 +47,7 @@ var (
Required: true,
},
&cli.Uint64Flag{
Name: "millisatsperbyte",
Name: "millisats-per-byte",
Usage: "the mSat/byte to pay for the transaction",
Value: 100,
},
Expand Down Expand Up @@ -91,7 +85,7 @@ func feeDepositAction(ctx *cli.Context) error {
}
defer cleanup()

numOfAddresses := ctx.Int64("num_of_addresses")
numOfAddresses := ctx.Int64("num-of-addresses")
reply, err := client.DeriveFeeAddresses(
context.Background(), &daemonv2.DeriveFeeAddressesRequest{
NumOfAddresses: numOfAddresses,
Expand Down Expand Up @@ -123,11 +117,6 @@ func feeListAddressesAction(ctx *cli.Context) error {
return nil
}

func feeClaimAction(ctx *cli.Context) error {
printDeprecatedWarn("")
return nil
}

func feeWithdrawAction(ctx *cli.Context) error {
client, cleanup, err := getOperatorClient(ctx)
if err != nil {
Expand All @@ -137,7 +126,7 @@ func feeWithdrawAction(ctx *cli.Context) error {

receivers := ctx.StringSlice("receivers")
password := ctx.String("password")
mSatsPerByte := ctx.Uint64("millisatsperbyte")
mSatsPerByte := ctx.Uint64("millisats-per-byte")
outputs, err := parseOutputs(receivers)
if err != nil {
return err
Expand Down
12 changes: 6 additions & 6 deletions cmd/tdex/feefragmenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (
Usage: "generate some address(es) to receive funds",
Flags: []cli.Flag{
&cli.UintFlag{
Name: "num_of_addresses",
Name: "num-of-addresses",
Usage: "the number of addresses to generate",
},
},
Expand All @@ -46,7 +46,7 @@ var (
Usage: "split fee fragmenter funds and make them deposits of the fee account",
Flags: []cli.Flag{
&cli.IntFlag{
Name: "num_fragments",
Name: "num-fragments",
Usage: "Number of fragmented utxos to generate from fee fragmenter account balance",
},
},
Expand All @@ -61,7 +61,7 @@ var (
Usage: "list of withdrawal receivers as {aseet, amount, address}",
},
&cli.Uint64Flag{
Name: "millisatsperbyte",
Name: "millisats-per-byte",
Usage: "the mSat/byte to pay for the transaction",
Value: 100,
},
Expand Down Expand Up @@ -101,7 +101,7 @@ func feeFragmenterDepositAction(ctx *cli.Context) error {
}
defer cleanup()

numOfAddresses := ctx.Int64("num_of_addresses")
numOfAddresses := ctx.Int64("num-of-addresses")
resp, err := client.DeriveFeeFragmenterAddresses(
context.Background(), &daemonv2.DeriveFeeFragmenterAddressesRequest{
NumOfAddresses: numOfAddresses,
Expand Down Expand Up @@ -140,7 +140,7 @@ func feeFragmenterSplitFundsAction(ctx *cli.Context) error {
}
defer cleanup()

numFragments := ctx.Int("num_fragments")
numFragments := ctx.Int("num-fragments")

stream, err := client.FeeFragmenterSplitFunds(
context.Background(), &daemonv2.FeeFragmenterSplitFundsRequest{
Expand Down Expand Up @@ -176,7 +176,7 @@ func feeFragmenterWithdrawAction(ctx *cli.Context) error {

receivers := ctx.StringSlice("receivers")
password := ctx.String("password")
mSatsPerByte := ctx.Uint64("millisatsperbyte")
mSatsPerByte := ctx.Uint64("millisats-per-byte")
outputs, err := parseOutputs(receivers)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions cmd/tdex/listdeposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var listdeposits = cli.Command{
Usage: "get a list of all deposits for a wallet account",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "account_name",
Name: "account-name",
Usage: "the name of the account for which listing deposits",
Required: true,
},
Expand All @@ -21,7 +21,7 @@ var listdeposits = cli.Command{
Usage: "the number of the page to be listed. If omitted, the entire list is returned",
},
&cli.Int64Flag{
Name: "page_size",
Name: "page-size",
Usage: "the size of the page",
Value: 10,
},
Expand All @@ -36,9 +36,9 @@ func listDepositsAction(ctx *cli.Context) error {
}
defer cleanup()

accountName := ctx.String("account_name")
accountName := ctx.String("account-name")
pageNumber := ctx.Int64("page")
pageSize := ctx.Int64("page_size")
pageSize := ctx.Int64("page-size")
var page *daemonv2.Page
if pageNumber > 0 {
page = &daemonv2.Page{
Expand Down
4 changes: 2 additions & 2 deletions cmd/tdex/listtrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var listtrades = cli.Command{
Usage: "the number of the page to be listed. If omitted, the entire list is returned",
},
&cli.Uint64Flag{
Name: "page_size",
Name: "page-size",
Usage: "the size of the page",
Value: 10,
},
Expand All @@ -34,7 +34,7 @@ func listTradesAction(ctx *cli.Context) error {
defer cleanup()

pageNumber := ctx.Int64("page")
pageSize := ctx.Int64("page_size")
pageSize := ctx.Int64("page-size")
var page *daemonv2.Page
if pageNumber > 0 {
page = &daemonv2.Page{
Expand Down
8 changes: 4 additions & 4 deletions cmd/tdex/listutxos.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var listutxos = cli.Command{
Usage: "get a list of all utxos for a wallet account",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "account_name",
Name: "account-name",
Usage: "the name of the wallet account for which listing utxos",
Required: true,
},
Expand All @@ -21,7 +21,7 @@ var listutxos = cli.Command{
Usage: "the number of the page to be listed. If omitted, the entire list is returned",
},
&cli.Int64Flag{
Name: "page_size",
Name: "page-size",
Usage: "the size of the page",
Value: 10,
},
Expand All @@ -36,9 +36,9 @@ func listUtxosAction(ctx *cli.Context) error {
}
defer cleanup()

accountName := ctx.String("account_name")
accountName := ctx.String("account-name")
pageNumber := ctx.Int64("page")
pageSize := ctx.Int64("page_size")
pageSize := ctx.Int64("page-size")
var page *daemonv2.Page
if pageNumber > 0 {
page = &daemonv2.Page{
Expand Down
8 changes: 4 additions & 4 deletions cmd/tdex/listwithdrawals.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var listwithdrawals = cli.Command{
Usage: "get a list of all withdrawals for a wallet account",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "account_name",
Name: "account-name",
Usage: "the name of the wallet account for which listing withdrawals",
Required: true,
},
Expand All @@ -21,7 +21,7 @@ var listwithdrawals = cli.Command{
Usage: "the number of the page to be listed. If omitted, the entire list is returned",
},
&cli.Uint64Flag{
Name: "page_size",
Name: "page-size",
Usage: "the size of the page",
Value: 10,
},
Expand All @@ -36,9 +36,9 @@ func listWithdrawalsAction(ctx *cli.Context) error {
}
defer cleanup()

accountName := ctx.String("account_name")
accountName := ctx.String("account-name")
pageNumber := ctx.Int64("page")
pageSize := ctx.Int64("page_size")
pageSize := ctx.Int64("page-size")
var page *daemonv2.Page
if pageNumber > 0 {
page = &daemonv2.Page{
Expand Down
9 changes: 0 additions & 9 deletions cmd/tdex/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func main() {
&status,
&changepassword,
&getwalletinfo,
&walletAccount,
&feeAccount,
&feeFragmenterAccount,
&marketAccount,
Expand Down Expand Up @@ -349,14 +348,6 @@ func cleanAndExpandPath(path string) string {
return filepath.Clean(os.ExpandEnv(path))
}

func printDeprecatedWarn(newCmd string) {
colorYellow := "\033[33m"
fmt.Println(fmt.Sprintf(
"%sWarning: this command is deprecated and will be removed in the next "+
"version.\nInstead, use the new command '%s'", string(colorYellow), newCmd,
))
}

type invalidUsageError struct {
ctx *cli.Context
command string
Expand Down
Loading

0 comments on commit bf3b384

Please sign in to comment.