github.com/decred/politeia@v1.4.0/politeiawww/cmd/pictl/cmdcomments.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 cmv1 "github.com/decred/politeia/politeiawww/api/comments/v1" 9 pclient "github.com/decred/politeia/politeiawww/client" 10 ) 11 12 // cmdComments retreives the comments for the specified proposal. 13 type cmdComments struct { 14 Args struct { 15 Token string `positional-arg-name:"token"` // Censorship token 16 } `positional-args:"true" required:"true"` 17 } 18 19 // Execute executes the cmdComments command. 20 // 21 // This function satisfies the go-flags Commander interface. 22 func (c *cmdComments) Execute(args []string) error { 23 // Setup client 24 opts := pclient.Opts{ 25 HTTPSCert: cfg.HTTPSCert, 26 Cookies: cfg.Cookies, 27 HeaderCSRF: cfg.CSRF, 28 Verbose: cfg.Verbose, 29 RawJSON: cfg.RawJSON, 30 } 31 pc, err := pclient.New(cfg.Host, opts) 32 if err != nil { 33 return err 34 } 35 36 // Get comments 37 cm := cmv1.Comments{ 38 Token: c.Args.Token, 39 } 40 cr, err := pc.Comments(cm) 41 if err != nil { 42 return err 43 } 44 45 // Print comments 46 for _, v := range cr.Comments { 47 printComment(v) 48 printf("\n") 49 } 50 51 return nil 52 } 53 54 // commentsHelpMsg is printed to stdout by the help command. 55 const commentsHelpMsg = `comments "token" 56 57 Get the comments for a record. 58 59 If the record is unvetted, the --unvetted flag must be used. Retrieving the 60 comments on an unvetted record requires the user be either an admin or the 61 record author. 62 63 Arguments: 64 1. token (string, required) Proposal censorship token 65 `