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.

205 lines
4.5 KiB

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 = `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
`
fmt.Printf(helpMsg, os.Args[0])
}
func parseFlagsAndExecute() {
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
err error
)
flag.Usage = HelpMsg
err = Helper.CheckRoot()
if err != nil {
fmt.Println(Color.Fatal(err))
return
}
err = Database.InitDB()
if err != nil {
panic(err)
}
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)
}
err = Filesystem.ShowFilesystemDiff(rootPath)
if err != nil {
panic(err)
}
return
}
if addFileDiffFlag || addFileDiffFlagLong {
if len(flag.Args()) > 1 || len(flag.Args()) < 1 {
fmt.Println(Color.Fatal("Must supply one argument"))
flag.Usage()
return
}
err = Filesystem.PickFiles(flag.Arg(0))
if err != nil {
panic(err)
}
return
}
if commitAddedFilesFlag || commitAddedFilesFlagLong {
err = Filesystem.CommitFiles()
if err != nil {
panic(err)
}
return
}
if resetAddedFilesFlag || resetAddedFilesFlagLong {
err = Filesystem.ResetAllPickedFiles()
if err != nil {
panic(err)
}
return
}
if createPackageFlag || createPackageFlagLong {
err = Package.CreatePackage()
if err != nil {
panic(err)
}
return
}
if installLocalPackageFlag || installLocalPackageFlagLong {
err = Package.InstallPackage(flag.Args())
if err != nil {
panic(err)
}
return
}
if uninstallPackageFlag || uninstallPackageFlagLong {
err = Package.UninstallPackage(flag.Args())
if err != nil {
panic(err)
}
return
}
flag.Usage()
fmt.Println(Color.Fatal("Nothing to do"))
}
func main() {
parseFlagsAndExecute()
}