github.com/decred/politeia@v1.4.0/politeiawww/cmd/pictl/cmdproposaldetails.go (about)

     1  // Copyright (c) 2020-2021 The Decred developers
     2  // Use of this source code is governed by an ISC
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	rcv1 "github.com/decred/politeia/politeiawww/api/records/v1"
     9  	pclient "github.com/decred/politeia/politeiawww/client"
    10  )
    11  
    12  // proposalDetails retrieves a full proposal record.
    13  type cmdProposalDetails struct {
    14  	Args struct {
    15  		Token   string `positional-arg-name:"token"`
    16  		Version uint32 `postional-arg-name:"version" optional:"true"`
    17  	} `positional-args:"true"`
    18  }
    19  
    20  // Execute executes the cmdProposalDetails command.
    21  //
    22  // This function satisfies the go-flags Commander interface.
    23  func (c *cmdProposalDetails) Execute(args []string) error {
    24  	// Setup client
    25  	opts := pclient.Opts{
    26  		HTTPSCert:  cfg.HTTPSCert,
    27  		Cookies:    cfg.Cookies,
    28  		HeaderCSRF: cfg.CSRF,
    29  		Verbose:    cfg.Verbose,
    30  		RawJSON:    cfg.RawJSON,
    31  	}
    32  	pc, err := pclient.New(cfg.Host, opts)
    33  	if err != nil {
    34  		return err
    35  	}
    36  
    37  	// Get proposal details
    38  	d := rcv1.Details{
    39  		Token:   c.Args.Token,
    40  		Version: c.Args.Version,
    41  	}
    42  	r, err := pc.RecordDetails(d)
    43  	if err != nil {
    44  		return err
    45  	}
    46  
    47  	// Print proposal to stdout
    48  	err = printProposal(*r)
    49  	if err != nil {
    50  		return err
    51  	}
    52  
    53  	return nil
    54  }
    55  
    56  // proposalDetailsHelpMsg is printed to stdout by the help command.
    57  const proposalDetailsHelpMsg = `proposaldetails [flags] "token" "version"
    58  
    59  Retrieve a full proposal record.
    60  
    61  This command accepts both the full tokens or the shortened token prefixes.
    62  
    63  Arguments:
    64  1. token  (string, required)  Proposal token.
    65  `