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

Method Link

cli/link.go:10–57  ·  view source on GitHub ↗

Link allows the links to be created on the Index

()

Source from the content-addressed store, hash-verified

8
9// Link allows the links to be created on the Index
10func (s SpreadCli) Link() *cli.Command {
11 return &cli.Command{
12 Name: "link",
13 Usage: "spread link <target-url> <attach-point>",
14 Description: "Create/remove links on Index",
15 Action: func(c *cli.Context) {
16 targetUrl := c.Args().First()
17 if len(targetUrl) == 0 {
18 s.fatalf("A target URL must be specified")
19 }
20
21 target, err := data.ParseSRI(targetUrl)
22 if err != nil {
23 s.fatalf("Error using target: %v", err)
24 }
25
26 attachPoint := c.Args().Get(1)
27 if len(attachPoint) == 0 {
28 s.fatalf("An attach point must be specified")
29 }
30
31 attach, err := data.ParseSRI(attachPoint)
32 if err != nil {
33 s.fatalf("Error using attach-point: %v", err)
34 }
35
36 proj := s.projectOrDie()
37 index, err := proj.Index()
38 if err != nil {
39 s.fatalf("Error retrieving index: %v", err)
40 }
41
42 doc, ok := index[attach.Path]
43 if !ok {
44 s.fatalf("Path '%s' not found", attach.Path)
45 }
46
47 link := data.NewLink("test", target, false)
48 if err = data.CreateLinkInDocument(doc, link, attach); err != nil {
49 s.fatalf("Could not create link: %v", err)
50 }
51
52 if err = proj.AddDocumentToIndex(doc); err != nil {
53 s.fatalf("Failed to add object to Git index: %v", err)
54 }
55 },
56 }
57}

Callers

nothing calls this directly

Calls 5

fatalfMethod · 0.95
projectOrDieMethod · 0.95
IndexMethod · 0.80
AddDocumentToIndexMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected