PackageManager just because
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.

177 lines
3.5 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "os"
  6. "PackageManager/Client/Database"
  7. "PackageManager/Client/Filesystem"
  8. "PackageManager/Client/Package"
  9. "PackageManager/Color"
  10. "PackageManager/Helper"
  11. "PackageManager/Variables"
  12. )
  13. func HelpMsg() {
  14. var helpMsg string
  15. helpMsg = `Usage of %s:
  16. General:
  17. -V | -verbose
  18. Verbose output
  19. Filesystem diff:
  20. -Af | -add-files
  21. Add files
  22. -Cf | -commit
  23. Add files
  24. -Fd | -fs-diff
  25. Filesystem diff
  26. -Rf | -reset
  27. Reset added files
  28. -Cp | -create-pkg
  29. Create package from fs diff
  30. `
  31. helpMsg = fmt.Sprintf(helpMsg, os.Args[0])
  32. fmt.Println(helpMsg)
  33. }
  34. func main() {
  35. var (
  36. getFilesystemDiffFlag bool
  37. getFilesystemDiffFlagLong bool
  38. addFileDiffFlag bool
  39. addFileDiffFlagLong bool
  40. commitAddedFilesFlag bool
  41. commitAddedFilesFlagLong bool
  42. resetAddedFilesFlag bool
  43. resetAddedFilesFlagLong bool
  44. createPackageFlag bool
  45. createPackageFlagLong bool
  46. verboseOutputFlag bool
  47. verboseOutputFlagLong bool
  48. e error
  49. )
  50. flag.Usage = HelpMsg
  51. e = Helper.CheckRoot()
  52. if e != nil {
  53. fmt.Println(Color.Fatal(e))
  54. return
  55. }
  56. e = Database.InitDB()
  57. if e != nil {
  58. panic(e)
  59. }
  60. // TODO: Rework usage function
  61. // Initialise flags
  62. flag.BoolVar(&verboseOutputFlag, "V", false, "Verbose output")
  63. flag.BoolVar(&verboseOutputFlagLong, "verbose", false, "Verbose output")
  64. flag.BoolVar(&getFilesystemDiffFlag, "Fd", false, "Filesystem diff")
  65. flag.BoolVar(&getFilesystemDiffFlagLong, "fs-diff", false, "Filesystem diff")
  66. flag.BoolVar(&addFileDiffFlag, "Af", false, "Add files")
  67. flag.BoolVar(&addFileDiffFlagLong, "add-files", false, "Add files")
  68. flag.BoolVar(&commitAddedFilesFlag, "Cf", false, "Commit files")
  69. flag.BoolVar(&commitAddedFilesFlagLong, "commit", false, "Commit files")
  70. flag.BoolVar(&resetAddedFilesFlag, "Rf", false, "Reset added files")
  71. flag.BoolVar(&resetAddedFilesFlagLong, "reset", false, "Reset added files")
  72. flag.BoolVar(&createPackageFlag, "Cp", false, "Create package from fs diff")
  73. flag.BoolVar(&createPackageFlagLong, "create-pkg", false, "Create package from fs diff")
  74. flag.Parse()
  75. Variables.VerboseOutput = verboseOutputFlag || verboseOutputFlagLong
  76. if getFilesystemDiffFlag || getFilesystemDiffFlagLong {
  77. var rootPath string = Variables.RootDir
  78. if len(flag.Args()) > 1 {
  79. // TODO: Fix this msg
  80. fmt.Println(Color.Fatal("Option takes one optional argument"))
  81. flag.Usage()
  82. return
  83. }
  84. if len(flag.Args()) == 1 {
  85. rootPath = flag.Arg(0)
  86. }
  87. e = Filesystem.ShowFilesystemDiff(rootPath)
  88. if e != nil {
  89. panic(e)
  90. }
  91. return
  92. }
  93. if addFileDiffFlag || addFileDiffFlagLong {
  94. if len(flag.Args()) > 1 && len(flag.Args()) < 1 {
  95. fmt.Println(Color.Fatal("Must supply one argument"))
  96. flag.Usage()
  97. return
  98. }
  99. e = Filesystem.PickFiles(flag.Arg(0))
  100. if e != nil {
  101. panic(e)
  102. }
  103. return
  104. }
  105. if commitAddedFilesFlag || commitAddedFilesFlagLong {
  106. e = Filesystem.CommitFiles()
  107. if e != nil {
  108. panic(e)
  109. }
  110. return
  111. }
  112. if resetAddedFilesFlag || resetAddedFilesFlagLong {
  113. e = Filesystem.ResetAllPickedFiles()
  114. if e != nil {
  115. panic(e)
  116. }
  117. return
  118. }
  119. if createPackageFlag || createPackageFlagLong {
  120. e = Package.CreatePackage()
  121. if e != nil {
  122. panic(e)
  123. }
  124. return
  125. }
  126. /*
  127. if installLocalPackageFlag || installLocalPackageFlagLong {
  128. e = Package.InstallPackage(flag.Args())
  129. if e != nil {
  130. panic(e)
  131. }
  132. return
  133. }
  134. */
  135. flag.Usage()
  136. fmt.Println(Color.Fatal("Nothing to do"))
  137. //e := Archive.TarGzip("/tmp/test", "/tmp/test.tar.gz")
  138. //e := Archive.UntarGzip("/tmp/test.tar.gz", "/tmp/test")
  139. //fmt.Println(e)
  140. }