You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
2.7 KiB

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