This repository has been archived by the owner on Apr 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
commands.go
121 lines (103 loc) · 3.26 KB
/
commands.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Bash commands to be executed by the application.
package main
import (
"fmt"
"net/url"
"os/exec"
"github.com/logrusorgru/aurora"
)
func run(cmd *exec.Cmd, path string, errMessage string, cmdMessage ...interface{}) (out []byte, err error) {
// Default path
if path != "." {
cmd.Dir = path
}
out, err = cmd.Output()
if err != nil {
fmt.Println(errMessage)
fmt.Println(cmdMessage...)
// Log the `ExitError`
ee, ok := err.(*exec.ExitError)
if ok {
fmt.Println(string(ee.Stderr))
}
fmt.Println(string(out))
return
}
return
}
func ipfsClusterAdd(link string, rmin string, rmax string, uuid string) (out []byte, err error) {
return run(
exec.Command("ipfs-cluster-ctl", "add", "--recursive", "--quieter", "--chunker=rabin", "--cid-version=1", "--name", link, "--replication-min", rmin, "--replication-max", rmax, uuid),
dirHome+dirGit,
"Couldn't add the repository to IPFS.",
aurora.Bold("Command :"), "ipfs-cluster-ctl", "add", "--recursive", "--quieter", "--chunker=rabin", "--cid-version=1", "--name", aurora.Blue(link), "--replication-min", aurora.Bold(rmin), "--replication-max", aurora.Bold(rmax), uuid,
)
}
func ipfsKeyGen(link string) (out []byte, err error) {
escaped := url.PathEscape(link)
return run(
exec.Command("ipfs", "key", "gen", "--type", "ed25519", escaped),
".",
"Couldn't generate a new key.",
aurora.Bold("Command :"), "ipfs", "key", "gen", "--type", "ed25519", aurora.Blue(escaped),
)
}
func ipfsKeyRm(key string) (out []byte, err error) {
return run(
exec.Command("ipfs", "key", "rm", key),
".",
"Couldn't remove a key.",
aurora.Bold("Command :"), "ipfs", "key", "rm", key,
)
}
func ipfsKeyRmName(name string) (out []byte, err error) {
return ipfsKeyRm(url.PathEscape(name))
}
func ipfsNamePublish(key string, ipfs string) (out []byte, err error) {
return run(
exec.Command("ipfs", "name", "publish", "--key", key, "--quieter", "/ipfs/"+ipfs),
".",
"Couldn't publish on IPNS.",
aurora.Bold("Command :"), "ipfs", "name", "publish", "--key", key, "--quieter", aurora.Cyan("/ipfs/"+ipfs),
)
}
func gitClone(link string, uuid string) (out []byte, err error) {
return run(
exec.Command("git", "clone", link, uuid),
dirHome+dirGit,
"Couldn't clone the repository.",
aurora.Bold("Command :"), "git", "clone", aurora.Blue(link), uuid,
)
}
func gitPull(uuid string) (out []byte, err error) {
return run(
exec.Command("git", "-C", uuid, "pull"),
dirHome+dirGit,
"Couldn't pull the repository.",
aurora.Bold("Command :"), "git", "-C", uuid, "pull",
)
}
func ipfsClusterRm(ipfs string) (out []byte, err error) {
return run(
exec.Command("ipfs-cluster-ctl", "pin", "rm", ipfs),
".",
"Couldn't remove the repository from IPFS.",
aurora.Bold("Command :"), "ipfs-cluster-ctl", "pin", "rm", aurora.Cyan(ipfs),
)
}
func rm(uuid string) (out []byte, err error) {
return run(
exec.Command("rm", "--force", "--recursive", uuid),
dirHome+dirGit,
"Couldn't delete the repository.",
aurora.Bold("Command :"), "rm", "--force", "--recursive", uuid,
)
}
func ipfsSwarmConnect(address string) (out []byte, err error) {
return run(
exec.Command("ipfs", "swarm", "connect", address),
".",
"Couldn't connect to "+address+".",
aurora.Bold("Command :"), "ipfs", "swarm", "connect", aurora.Cyan(address),
)
}