|
|
- package main
-
- import (
- "flag"
- "fmt"
- "os"
-
- "PackageManager/Client/Database"
- "PackageManager/Client/Filesystem"
- "PackageManager/Color"
- "PackageManager/Helper"
- "PackageManager/Variables"
- )
-
- func HelpMsg() {
- var helpMsg string
- helpMsg = `Usage of %s:
-
- -Af | -add-files
- Add files
-
- -Cf | -commit
- Add files
-
- -Fd | -fs-diff
- Filesystem diff
-
- -Rf | -reset
- Reset added files
-
- -V | -verbose
- Verbose output
- `
- helpMsg = fmt.Sprintf(helpMsg, os.Args[0])
- fmt.Println(helpMsg)
- }
-
- func main() {
- var (
- getFilesystemDiffFlag bool
- getFilesystemDiffFlagLong bool
- addFileDiffFlag bool
- addFileDiffFlagLong bool
- commitAddedFilesFlag bool
- commitAddedFilesFlagLong bool
- resetAddedFilesFlag bool
- resetAddedFilesFlagLong bool
-
- verboseOutputFlag bool
- verboseOutputFlagLong bool
-
- e error
- )
-
- flag.Usage = HelpMsg
-
- e = Helper.CheckRoot()
- if e != nil {
- fmt.Println(Color.Fatal(e))
- return
- }
-
- e = Database.InitDB()
- if e != nil {
- panic(e)
- }
-
- // TODO: Rework usage function
-
- // Initialise flags
- flag.BoolVar(&verboseOutputFlag, "V", false, "Verbose output")
- flag.BoolVar(&verboseOutputFlagLong, "verbose", false, "Verbose output")
-
- flag.BoolVar(&getFilesystemDiffFlag, "Fd", false, "Filesystem diff")
- flag.BoolVar(&getFilesystemDiffFlagLong, "fs-diff", false, "Filesystem diff")
-
- flag.BoolVar(&addFileDiffFlag, "Af", false, "Add files")
- flag.BoolVar(&addFileDiffFlagLong, "add-files", false, "Add files")
-
- flag.BoolVar(&commitAddedFilesFlag, "Cf", false, "Commit files")
- flag.BoolVar(&commitAddedFilesFlagLong, "commit", false, "Commit files")
-
- flag.BoolVar(&resetAddedFilesFlag, "Rf", false, "Reset added files")
- flag.BoolVar(&resetAddedFilesFlagLong, "reset", false, "Reset added files")
-
- flag.Parse()
-
- Variables.VerboseOutput = verboseOutputFlag || verboseOutputFlagLong
-
- if getFilesystemDiffFlag || getFilesystemDiffFlagLong {
- var rootPath string = Variables.RootDir
- if len(flag.Args()) > 1 {
- // TODO: Fix this msg
- fmt.Println(Color.Fatal("Option takes one optional argument"))
- flag.Usage()
- return
- }
-
- if len(flag.Args()) == 1 {
- rootPath = flag.Arg(0)
- }
-
- e = Filesystem.ShowFilesystemDiff(rootPath)
- if e != nil {
- panic(e)
- }
-
- return
- }
-
- if addFileDiffFlag || addFileDiffFlagLong {
- if len(flag.Args()) > 1 && len(flag.Args()) < 1 {
- fmt.Println(Color.Fatal("Must supply one argument"))
- flag.Usage()
- return
- }
- e = Filesystem.PickFiles(flag.Arg(0))
- if e != nil {
- panic(e)
- }
- return
- }
-
- if commitAddedFilesFlag || commitAddedFilesFlagLong {
- e = Filesystem.CommitFiles()
- if e != nil {
- panic(e)
- }
- return
- }
-
- if resetAddedFilesFlag || resetAddedFilesFlagLong {
- e = Filesystem.ResetAllPickedFiles()
- if e != nil {
- panic(e)
- }
- return
- }
-
- /*
- if createPackageFlag || createPackageFlagLong {
- e = Package.CreatePackage()
- if e != nil {
- panic(e)
- }
- return
- }
-
- if installLocalPackageFlag || installLocalPackageFlagLong {
- e = Package.InstallPackage(flag.Args())
- if e != nil {
- panic(e)
- }
- return
- }
- */
-
- flag.Usage()
- fmt.Println(Color.Fatal("Nothing to do"))
-
- //e := Archive.TarGzip("/tmp/test", "/tmp/test.tar.gz")
- //e := Archive.UntarGzip("/tmp/test.tar.gz", "/tmp/test")
- //fmt.Println(e)
- }
|