github.com/jfrog/jfrog-cli-core/v2@v2.52.0/plugins/signature.go (about)

     1  package plugins
     2  
     3  import (
     4  	"encoding/json"
     5  	"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
     6  	clientutils "github.com/jfrog/jfrog-client-go/utils"
     7  	"github.com/jfrog/jfrog-client-go/utils/log"
     8  	"github.com/urfave/cli"
     9  )
    10  
    11  const SignatureCommandName = "hidden-plugin-signature"
    12  
    13  // Adds a hidden command to every built plugin.
    14  // The command will later be used by the CLI to retrieve the plugin's signature to show in the CLI's help command.
    15  func addHiddenPluginSignatureCommand(baseApp *cli.App) {
    16  	cmd := cli.Command{
    17  		Name:     SignatureCommandName,
    18  		Hidden:   true,
    19  		HideHelp: true,
    20  		Action: func(c *cli.Context) error {
    21  			signature := components.PluginSignature{
    22  				Name:  baseApp.Name,
    23  				Usage: baseApp.Description,
    24  			}
    25  			content, err := json.Marshal(signature)
    26  			if err == nil {
    27  				log.Output(clientutils.IndentJson(content))
    28  			}
    29  			return err
    30  		},
    31  	}
    32  	baseApp.Commands = append(baseApp.Commands, cmd)
    33  }