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.

208 lines
4.3 KiB

package main
import (
"flag"
"fmt"
"os"
"PackageManager/Client/Database"
"PackageManager/Client/Filesystem"
"PackageManager/Client/Package"
"PackageManager/Color"
"PackageManager/Helper"
"PackageManager/Variables"
)
func InitConfigDir() error {
var (
e error
)
_, e = os.Stat(Variables.ConfigDir)
if os.IsNotExist(e) {
os.MkdirAll(Variables.ConfigDir, 0644)
}
return e
}
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
-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
ignoreDepsCheckFlag bool
verboseOutputFlag bool
verboseOutputFlagLong bool
e error
)
flag.Usage = HelpMsg
e = Helper.CheckRoot()
if e != nil {
fmt.Println(Color.Fatal(e))
return
}
e = InitConfigDir()
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(&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
}
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)
}