From f3c8311b2827d885c90b461e2f4dbbc8abb6361e Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 25 Nov 2020 15:31:19 -0800 Subject: [PATCH] lncli: add policy type flags to `wtclient policy` --- cmd/lncli/wtclient.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/cmd/lncli/wtclient.go b/cmd/lncli/wtclient.go index 5f887fc9..f831403a 100644 --- a/cmd/lncli/wtclient.go +++ b/cmd/lncli/wtclient.go @@ -250,19 +250,44 @@ var policyCommand = cli.Command{ Name: "policy", Usage: "Display the active watchtower client policy configuration.", Action: actionDecorator(policy), + Flags: []cli.Flag{ + cli.BoolFlag{ + Name: "legacy", + Usage: "Retrieve the legacy tower client's current " + + "policy. (default)", + }, + cli.BoolFlag{ + Name: "anchor", + Usage: "Retrieve the anchor tower client's current policy.", + }, + }, } func policy(ctx *cli.Context) error { // Display the command's help message if the number of arguments/flags // is not what we expect. - if ctx.NArg() > 0 || ctx.NumFlags() > 0 { + if ctx.NArg() > 0 || ctx.NumFlags() > 1 { return cli.ShowCommandHelp(ctx, "policy") } + var policyType wtclientrpc.PolicyType + switch { + case ctx.Bool("anchor"): + policyType = wtclientrpc.PolicyType_ANCHOR + case ctx.Bool("legacy"): + policyType = wtclientrpc.PolicyType_LEGACY + + // For backwards compatibility with original rpc behavior. + default: + policyType = wtclientrpc.PolicyType_LEGACY + } + client, cleanUp := getWtclient(ctx) defer cleanUp() - req := &wtclientrpc.PolicyRequest{} + req := &wtclientrpc.PolicyRequest{ + PolicyType: policyType, + } resp, err := client.Policy(context.Background(), req) if err != nil { return err