func extractPathArgs(ctx *cli.Context) (string, string, error) {
	networkStr := strings.ToLower(ctx.GlobalString("network"))
	_, err := lndclient.Network(networkStr).ChainParams()
	if err != nil {
		return "", "", err
	}
	baseDir := lncfg.CleanAndExpandPath(ctx.GlobalString(baseDirFlag.Name))
	tlsCertPath := lncfg.CleanAndExpandPath(ctx.GlobalString(
		tlsCertFlag.Name,
	))
	macPath := lncfg.CleanAndExpandPath(ctx.GlobalString(
		macaroonPathFlag.Name,
	))
	if baseDir != pool.DefaultBaseDir || networkStr != pool.DefaultNetwork {
		tlsCertPath = filepath.Join(
			baseDir, networkStr, pool.DefaultTLSCertFilename,
		)
		macPath = filepath.Join(
			baseDir, networkStr, pool.DefaultMacaroonFilename,
		)
	}
	return tlsCertPath, macPath, nil
}
extractPathArgs parses the TLS certificate and macaroon paths from the
command.
package main
import (
	"bytes"
	"context"
	"encoding/hex"
	"errors"
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strconv"
	"strings"
	"github.com/btcsuite/btcutil"
	"github.com/lightninglabs/lndclient"
	"github.com/lightninglabs/pool"
	"github.com/lightninglabs/pool/poolrpc"
	"github.com/lightninglabs/protobuf-hex-display/json"
	"github.com/lightninglabs/protobuf-hex-display/jsonpb"
	"github.com/lightninglabs/protobuf-hex-display/proto"
	"github.com/lightningnetwork/lnd/lncfg"
	"github.com/lightningnetwork/lnd/macaroons"
	"github.com/urfave/cli"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials"
	"gopkg.in/macaroon.v2"
)
var (
	maxMsgRecvSize = grpc.MaxCallRecvMsgSize(1 * 1024 * 1024 * 200)
	defaultMacaroonTimeout int64 = 60
	baseDirFlag = cli.StringFlag{
		Name:  "basedir",
		Value: pool.DefaultBaseDir,
		Usage: "path to pool's base directory",
	}
	networkFlag = cli.StringFlag{
		Name: "network, n",
		Usage: "the network pool is running on e.g. mainnet, " +
			"testnet, etc.",
		Value: pool.DefaultNetwork,
	}
	tlsCertFlag = cli.StringFlag{
		Name:  "tlscertpath",
		Usage: "path to pool's TLS certificate",
		Value: pool.DefaultTLSCertPath,
	}
	macaroonPathFlag = cli.StringFlag{
		Name:  "macaroonpath",
		Usage: "path to macaroon file",
		Value: pool.DefaultMacaroonPath,
	}
)
const (
	defaultInitiator = "pool-cli"
)
type invalidUsageError struct {
	ctx     *cli.Context
	command string
}
func (e *invalidUsageError) Error() string {
	return fmt.Sprintf("invalid usage of command %s", e.command)
}
func printJSON(resp interface{}) {
	b, err := json.Marshal(resp)
	if err != nil {
		fatal(err)
	}
	var out bytes.Buffer
	_ = json.Indent(&out, b, "", "\t")
	out.WriteString("\n")
	_, _ = out.WriteTo(os.Stdout)
}
func printRespJSON(resp proto.Message) {  
	jsonMarshaler := &jsonpb.Marshaler{
		EmitDefaults: true,
		OrigName:     true,
		Indent:       "\t",  
	}
	jsonStr, err := jsonMarshaler.MarshalToString(resp)
	if err != nil {
		fmt.Println("unable to decode response: ", err)
		return
	}
	fmt.Println(jsonStr)
}
func fatal(err error) {
	var e *invalidUsageError
	if errors.As(err, &e) {
		_ = cli.ShowCommandHelp(e.ctx, e.command)
	} else {
		_, _ = fmt.Fprintf(os.Stderr, "[pool] %v\n", err)
	}
	os.Exit(1)
}
func main() {
	app := cli.NewApp()
	app.Version = pool.Version()
	app.Name = "pool"
	app.Usage = "control plane for your poold"
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "rpcserver",
			Value: "localhost:12010",
			Usage: "poold daemon address host:port",
		},
		networkFlag,
		baseDirFlag,
		tlsCertFlag,
		macaroonPathFlag,
	}
	app.Commands = append(app.Commands, accountsCommands...)
	app.Commands = append(app.Commands, ordersCommands...)
	app.Commands = append(app.Commands, sidecarCommands...)
	app.Commands = append(app.Commands, auctionCommands...)
	app.Commands = append(app.Commands, listAuthCommand)
	app.Commands = append(app.Commands, getInfoCommand)
	app.Commands = append(app.Commands, debugCommands...)
	app.Commands = append(app.Commands, stopDaemonCommand)
	err := app.Run(os.Args)
	if err != nil {
		fatal(err)
	}
}
var stopDaemonCommand = cli.Command{
	Name:  "stop",
	Usage: "gracefully shut down the daemon",
	Description: "Sends the stop command to the Pool trader daemon to " +
		"initiate a graceful shutdown",
	Action: stop,
}
func stop(ctx *cli.Context) error {
	client, cleanup, err := getClient(ctx)
	if err != nil {
		return err
	}
	defer cleanup()
	_, err = client.StopDaemon(
		context.Background(), &poolrpc.StopDaemonRequest{},
	)
	return err
}
func getClient(ctx *cli.Context) (poolrpc.TraderClient, func(),
	error) {
	rpcServer := ctx.GlobalString("rpcserver")
	tlsCertPath, macaroonPath, err := extractPathArgs(ctx)
	if err != nil {
		return nil, nil, err
	}
	conn, err := getClientConn(rpcServer, tlsCertPath, macaroonPath)
	if err != nil {
		return nil, nil, err
	}
	cleanup := func() { _ = conn.Close() }
	traderClient := poolrpc.NewTraderClient(conn)
	return traderClient, cleanup, nil
}
func parseAmt(text string) (btcutil.Amount, error) {
	amtInt64, err := strconv.ParseInt(text, 10, 64)
	if err != nil {
		return 0, fmt.Errorf("invalid amt value: %v", err)
	}
	return btcutil.Amount(amtInt64), nil
}