github.com/decred/politeia@v1.4.0/politeiawww/cmd/pictl/cmdproposalsummaries.go (about) 1 // Copyright (c) 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 piv1 "github.com/decred/politeia/politeiawww/api/pi/v1" 9 pclient "github.com/decred/politeia/politeiawww/client" 10 ) 11 12 // cmdPropsoalSummaries retrieves the summaries for the provided proposal 13 // tokens. 14 type cmdProposalSummaries struct { 15 Args struct { 16 Tokens []string `positional-arg-name:"tokens"` 17 } `positional-args:"true" required:"true"` 18 } 19 20 // Execute executes the cmdProposalSummaries command. 21 // 22 // This function satisfies the go-flags Commander interface. 23 func (c *cmdProposalSummaries) Execute(args []string) error { 24 // Setup client 25 opts := pclient.Opts{ 26 HTTPSCert: cfg.HTTPSCert, 27 Verbose: cfg.Verbose, 28 RawJSON: cfg.RawJSON, 29 } 30 pc, err := pclient.New(cfg.Host, opts) 31 if err != nil { 32 return err 33 } 34 35 // Get vote summaries 36 s := piv1.Summaries{ 37 Tokens: c.Args.Tokens, 38 } 39 sr, err := pc.PiSummaries(s) 40 if err != nil { 41 return err 42 } 43 44 // Print summaries 45 for k, v := range sr.Summaries { 46 printProposalSummary(k, v) 47 printf("-----\n") 48 } 49 50 return nil 51 } 52 53 // proposalSummariesHelpMsg is printed to stdout by the help command. 54 const proposalSummariesHelpMsg = `proposalsummaries "tokens..." 55 56 Fetch the proposal summaries for the provided tokens. This command accepts both 57 full length tokens and token prefixes. 58 59 Example usage: 60 $ pictl proposalsummaries cda97ace0a476514 71dd3a110500fb6a 61 $ pictl proposalsummaries cda97ac 71dd3a1`