@ -0,0 +1 @@ | |||
*.db |
@ -0,0 +1,115 @@ | |||
package Package | |||
import ( | |||
"errors" | |||
"fmt" | |||
"strconv" | |||
"strings" | |||
"PackageManager/Client/Filesystem" | |||
"PackageManager/Color" | |||
"PackageManager/Helper" | |||
) | |||
func CreatePackage() error { | |||
var ( | |||
dirtyFiles map[int]string | |||
newFiles map[int]string | |||
pkgFiles map[int]string = make(map[int]string) | |||
choices string | |||
choicesSplit []string | |||
filePath string | |||
pkgName string | |||
pkgVersion string | |||
index int | |||
ok bool | |||
e error | |||
) | |||
fmt.Println("Initialising package creation...") | |||
dirtyFiles, newFiles, e = Filesystem.GetFilesystemDiff() | |||
if e != nil { | |||
return e | |||
} | |||
fmt.Println("\nModified files...") | |||
for i, file := range dirtyFiles { | |||
fmt.Printf( | |||
"\t%d - %s\n", | |||
i, | |||
Color.Red(file), | |||
) | |||
} | |||
fmt.Println("\nNew files...") | |||
for i, file := range newFiles { | |||
fmt.Printf( | |||
"\t%d - %s\n", | |||
i, | |||
Color.Red(file), | |||
) | |||
} | |||
fmt.Println("Please select the files you would like to use to create the package. Leave empty for all.") | |||
choices = Helper.Input() | |||
if choices == "" { | |||
for i, file := range dirtyFiles { | |||
pkgFiles[i] = file | |||
} | |||
for i, file := range newFiles { | |||
pkgFiles[i] = file | |||
} | |||
} else { | |||
choicesSplit = strings.Split(choices, ",") | |||
for _, i := range choicesSplit { | |||
index, e = strconv.Atoi(i) | |||
if e != nil { | |||
// TODO: Handle this error | |||
panic(e) | |||
} | |||
filePath, ok = dirtyFiles[index] | |||
if !ok { | |||
filePath, ok = dirtyFiles[index] | |||
if !ok { | |||
return errors.New("Invalid package selection") | |||
} | |||
} | |||
pkgFiles[index] = filePath | |||
} | |||
} | |||
fmt.Println("Please enter the package name:") | |||
pkgName = Helper.Input() | |||
if pkgName == "" { | |||
return errors.New("Invalid package name") | |||
} | |||
fmt.Println("Please enter the package version:") | |||
pkgVersion = Helper.Input() | |||
if pkgVersion == "" { | |||
return errors.New("Invalid package name") | |||
} | |||
fmt.Printf("Package Name: %s\n", pkgName) | |||
fmt.Printf("Package Version: %s\n", pkgVersion) | |||
fmt.Println("Files to be added") | |||
for i, file := range pkgFiles { | |||
fmt.Printf( | |||
"\t%d - %s\n", | |||
i, | |||
Color.Green(file), | |||
) | |||
} | |||
fmt.Println("Is this correct? [y/N]") | |||
if strings.ToLower(Helper.Input()) != "y" { | |||
return errors.New("User aborted") | |||
} | |||
return nil | |||
} |
@ -1,30 +1,59 @@ | |||
package main | |||
import ( | |||
"flag" | |||
"fmt" | |||
"PackageManager/Client/Database" | |||
"PackageManager/Client/Filesystem" | |||
"PackageManager/Client/Package" | |||
"PackageManager/Color" | |||
) | |||
func main() { | |||
var e error | |||
var ( | |||
updateFilesytemFlag bool | |||
updateFilesytemFlagLong bool | |||
createPackageFlag bool | |||
createPackageFlagLong bool | |||
e error | |||
) | |||
e = Database.InitDB() | |||
if e != nil { | |||
panic(e) | |||
} | |||
/* | |||
// Initialise flags | |||
flag.BoolVar(&updateFilesytemFlag, "Uf", false, "Update filesystem database") | |||
flag.BoolVar(&updateFilesytemFlagLong, "update-filesystem", false, "Update filesystem database") | |||
flag.BoolVar(&createPackageFlag, "Cp", false, "Create package") | |||
flag.BoolVar(&createPackageFlagLong, "create-package", false, "Create Package") | |||
flag.Parse() | |||
if updateFilesytemFlag || updateFilesytemFlagLong { | |||
e = Filesystem.UpdateFilesystemHash() | |||
if e != nil { | |||
panic(e) | |||
} | |||
*/ | |||
e = Filesystem.GetFilesystemDiff() | |||
if e != nil { | |||
panic(e) | |||
return | |||
} | |||
if createPackageFlag || createPackageFlagLong { | |||
e = Package.CreatePackage() | |||
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) | |||
@ -0,0 +1,58 @@ | |||
package Color | |||
import ( | |||
"fmt" | |||
"regexp" | |||
"runtime" | |||
) | |||
var ( | |||
Success = Green | |||
Info = Teal | |||
Warning = Yellow | |||
Fatal = Red | |||
) | |||
var ( | |||
Black = Color("\033[1;30m%s\033[0m") | |||
Red = Color("\033[1;31m%s\033[0m") | |||
Green = Color("\033[1;32m%s\033[0m") | |||
Yellow = Color("\033[1;33m%s\033[0m") | |||
Purple = Color("\033[1;34m%s\033[0m") | |||
Magenta = Color("\033[1;35m%s\033[0m") | |||
Teal = Color("\033[1;36m%s\033[0m") | |||
White = Color("\033[1;37m%s\033[0m") | |||
) | |||
func init() { | |||
if runtime.GOOS != "windows" { | |||
return | |||
} | |||
Black = Color("%s") | |||
Red = Color("%s") | |||
Green = Color("%s") | |||
Yellow = Color("%s") | |||
Purple = Color("%s") | |||
Magenta = Color("%s") | |||
Teal = Color("%s") | |||
White = Color("%s") | |||
} | |||
func Color(colorString string) func(...interface{}) string { | |||
sprint := func(args ...interface{}) string { | |||
return fmt.Sprintf(colorString, | |||
fmt.Sprint(args...)) | |||
} | |||
return sprint | |||
} | |||
func Strip(s string) string { | |||
var ( | |||
reg *regexp.Regexp | |||
res string | |||
) | |||
reg = regexp.MustCompile("\\033\\[.{1,4}m") | |||
res = reg.ReplaceAllString(s, "${1}") | |||
return res | |||
} |
@ -0,0 +1,24 @@ | |||
package Helper | |||
import ( | |||
"bufio" | |||
"os" | |||
"strings" | |||
) | |||
var ( | |||
reader *bufio.Reader = bufio.NewReader(os.Stdin) | |||
) | |||
func Input() string { | |||
var ( | |||
text string | |||
e error | |||
) | |||
text, e = reader.ReadString('\n') | |||
if e != nil { | |||
panic(e) | |||
} | |||
// convert CRLF to LF | |||
return strings.Replace(text, "\n", "", -1) | |||
} |