MCPcopy
hub / github.com/redspread/spread / Param

Method Param

cli/param.go:11–99  ·  view source on GitHub ↗

Param allows the parameters to be created on the Index

()

Source from the content-addressed store, hash-verified

9
10// Param allows the parameters to be created on the Index
11func (s SpreadCli) Param() *cli.Command {
12 return &cli.Command{
13 Name: "param",
14 Usage: "Set paramaters for field values in the index",
15 ArgsUsage: "<SRL> <name> <prompt>",
16 Flags: []cli.Flag{
17 cli.BoolFlag{
18 Name: "l",
19 Usage: "list parameters",
20 },
21 cli.StringFlag{
22 Name: "f",
23 Usage: "set Golang format string to use with arguments",
24 },
25 cli.StringFlag{
26 Name: "d",
27 Usage: "set default value, interpretted as JSON",
28 },
29 },
30 Action: func(c *cli.Context) {
31 if c.Bool("l") {
32 p := s.projectOrDie()
33 docs, err := p.Index()
34 if err != nil {
35 s.fatalf("Could not retrieve index: %v", err)
36 }
37
38 paramFields := data.ParameterFields(docs)
39 for _, field := range paramFields {
40 param := field.GetParam()
41 s.printf(" - Name: %s", param.Name)
42 s.printf(" Description: %s", param.Prompt)
43 s.printf(" Pattern: %s", param.Pattern)
44 if param.GetDefault() == nil {
45 s.printf(" Required: Yes")
46
47 }
48 }
49 return
50 }
51
52 if len(c.Args()) < 3 {
53 s.fatalf("an srl, name, and description must be provided")
54 }
55
56 targetUrl := c.Args().First()
57 if len(targetUrl) == 0 {
58 s.fatalf("A target SRI must be specified")
59 }
60
61 target, err := data.ParseSRI(targetUrl)
62 if err != nil {
63 s.fatalf("Error using target: %v", err)
64 }
65
66 proj := s.projectOrDie()
67 doc, err := proj.DocFromIndex(target.Path)
68 if err != nil {

Callers 2

GetMethod · 0.80
getMethod · 0.80

Calls 10

projectOrDieMethod · 0.95
fatalfMethod · 0.95
printfMethod · 0.95
GetDefaultMethod · 0.95
IndexMethod · 0.80
GetParamMethod · 0.80
DocFromIndexMethod · 0.80
AddDocumentToIndexMethod · 0.80
GetMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected