|
|
- package main
-
- import (
- "flag"
- "fmt"
- "os"
-
- "PackageManager/Client/Database"
- "PackageManager/Client/Filesystem"
- "PackageManager/Client/Package"
- "PackageManager/Color"
- "PackageManager/Helper"
- "PackageManager/Variables"
- )
-
- func HelpMsg() {
- var helpMsg string
- helpMsg = `Usage of %s:
-
- General:
- -V | -verbose
- Verbose output
-
- Filesystem diff:
- -Af | -add-files
- Add files
-
- -Cf | -commit
- Add files
-
- -Fd | -fs-diff
- Filesystem diff
-
- -Rf | -reset
- Reset added files
-
- -Cp | -create-pkg
- Create package from fs diff
-
- -Il | -install-local
- Install package from local tarball
-
- -Rl | -remove-local
- Remove package from local tarball
-
- -ignore-deps-check
- Skip dependancies check
- `
- 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
-
- createPackageFlag bool
- createPackageFlagLong bool
- installLocalPackageFlag bool
- installLocalPackageFlagLong bool
- uninstallPackageFlag bool
- uninstallPackageFlagLong bool
- ignoreDepsCheckFlag 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)
- }
-
- defer Database.DB.Close()
- defer Database.FsDB.Close()
-
- // 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.BoolVar(&createPackageFlag, "Cp", false, "Create package from fs diff")
- flag.BoolVar(&createPackageFlagLong, "create-pkg", false, "Create package from fs diff")
-
- flag.BoolVar(&installLocalPackageFlag, "Il", false, "Install package from local tarball")
- flag.BoolVar(&installLocalPackageFlagLong, "install-local", false, "Install package from local tarball")
-
- flag.BoolVar(&uninstallPackageFlag, "Rl", false, "Uninstall local package")
- flag.BoolVar(&uninstallPackageFlagLong, "remove-local", false, "Uninstall local package")
-
- flag.BoolVar(&ignoreDepsCheckFlag, "ignore-deps-check", false, "Ignore dependancies check")
-
- flag.Parse()
-
- Variables.VerboseOutput = verboseOutputFlag || verboseOutputFlagLong
- Variables.IgnoreDepsCheck = ignoreDepsCheckFlag
-
- if getFilesystemDiffFlag || getFilesystemDiffFlagLong {
- var rootPath string = Variables.RootDir
- if len(flag.Args()) > 1 {
- flag.Usage()
- fmt.Println(Color.Fatal("Option takes one optional argument"))
- 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
- }
-
- if uninstallPackageFlag || uninstallPackageFlagLong {
- e = Package.UninstallPackage(flag.Args())
- if e != nil {
- panic(e)
- }
- return
- }
-
- flag.Usage()
- fmt.Println(Color.Fatal("Nothing to do"))
- }
|