padArchiver/cli/main.go
cli/main.goRaw
1package main
2
3import (
4 "bufio"
5 "fmt"
6 "os"
7 "strings"
8
9 padArchiver ".."
10 "github.com/fatih/color"
11)
12
13const checkIcon = "\xE2\x9C\x94 "
14
15func main() {
16 asciiart := `
17.
18. _ _ _
19. | | /\ | | (_)
20 _ __ __ _ __| | / \ _ __ ___| |__ ___ _____ _ __
21| '_ \ / _ |/ _ | / /\ \ | '__/ __| '_ \| \ \ / / _ \ '__|
22| |_) | (_| | (_| |/ ____ \| | | (__| | | | |\ V / __/ |
23| .__/ \__,_|\__,_/_/ \_\_| \___|_| |_|_| \_/ \___|_| - cli
24| |
25|_|
26
27 `
28 color.Blue(asciiart)
29 fmt.Println(" v0.0.1")
30 color.Blue("https://github.com/arnaucode/padArchiver")
31 fmt.Println("")
32 fmt.Println("")
33 fmt.Println("")
34
35 newcommand := bufio.NewReader(os.Stdin)
36 fmt.Print("Please select command number")
37 options := `
38 1 - Store Pad (to local directory and IPFS)
39 2 - IPFS hash to file
40 0 - Exit cli
41option to select: `
42 for {
43 fmt.Print(options)
44
45 option, _ := newcommand.ReadString('\n')
46 option = strings.TrimSpace(option)
47
48 switch option {
49 case "1":
50 fmt.Println("selected 1 - Store Pad (to local directory and IPFS)")
51 option1()
52 break
53 case "2":
54 fmt.Println("selected 2 - IPFS hash to file")
55 option2()
56 break
57 case "0":
58 fmt.Println("selected 0 - exit cli")
59 os.Exit(3)
60 break
61 default:
62 fmt.Println("Invalid option")
63 break
64 }
65 }
66}
67func option1() {
68 newcommand := bufio.NewReader(os.Stdin)
69 fmt.Print(" Enter the repo ID (name): ")
70 repoID, _ := newcommand.ReadString('\n')
71 repoID = strings.Replace(repoID, "\n", "", -1)
72
73 newcommand = bufio.NewReader(os.Stdin)
74 fmt.Print(" Enter the pad link: ")
75 link, _ := newcommand.ReadString('\n')
76 link = strings.Replace(link, "\n", "", -1)
77
78 newcommand = bufio.NewReader(os.Stdin)
79 fmt.Print(" Enter the subdirectory: ")
80 subdirectory, _ := newcommand.ReadString('\n')
81 subdirectory = strings.Replace(subdirectory, "\n", "", -1)
82
83 newcommand = bufio.NewReader(os.Stdin)
84 fmt.Print(" Enter the pad Title: ")
85 title, _ := newcommand.ReadString('\n')
86 title = strings.Replace(title, "\n", "", -1)
87
88 repo := padArchiver.OpenRepo(repoID)
89
90 ipfsHash, err := repo.StorePad(link, subdirectory, title, true)
91 if err != nil {
92 color.Red(err.Error())
93 } else {
94 fmt.Println("IPFS hash: " + ipfsHash)
95 color.Green(checkIcon + "Pad stored in IPFS and Git")
96 }
97}
98func option2() {
99 newcommand := bufio.NewReader(os.Stdin)
100 fmt.Print(" Enter the IPFS hash: ")
101 hash, _ := newcommand.ReadString('\n')
102 hash = strings.Replace(hash, "\n", "", -1)
103 err := padArchiver.IpfsGet(hash, hash+".md")
104 if err != nil {
105 color.Red(err.Error())
106 } else {
107
108 color.Green(checkIcon + "File downloaded from IPFS network")
109 fmt.Print("File stored in: ")
110 color.Blue(padArchiver.GettedPads + "/" + hash + ".md")
111 }
112}