mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-16 10:36:12 +00:00
Replace 'human-readable' flag with 'show-bytes'
This commit is contained in:
+8
-8
@@ -55,7 +55,7 @@ func main() {
|
|||||||
currentFlagSet = flag.NewFlagSet("query", flag.ExitOnError)
|
currentFlagSet = flag.NewFlagSet("query", flag.ExitOnError)
|
||||||
currentFlagSet.StringP("root", "R", "/", "Operate on specified root directory")
|
currentFlagSet.StringP("root", "R", "/", "Operate on specified root directory")
|
||||||
currentFlagSet.BoolP("database", "d", false, "Show package information from remote databases")
|
currentFlagSet.BoolP("database", "d", false, "Show package information from remote databases")
|
||||||
currentFlagSet.BoolP("human-readable", "h", false, "Show package installed size in a human readable format")
|
currentFlagSet.BoolP("show-bytes", "b", false, "Show package installed size in bytes")
|
||||||
setupFlagsAndHelp(currentFlagSet, fmt.Sprintf("bpm %s <options>", subcommand), "Show information on the specified packages", os.Args[2:])
|
setupFlagsAndHelp(currentFlagSet, fmt.Sprintf("bpm %s <options>", subcommand), "Show information on the specified packages", os.Args[2:])
|
||||||
|
|
||||||
showPackageInfo()
|
showPackageInfo()
|
||||||
@@ -71,7 +71,7 @@ func main() {
|
|||||||
currentFlagSet.Bool("make-depends", false, "Show packages installed as make dependencies")
|
currentFlagSet.Bool("make-depends", false, "Show packages installed as make dependencies")
|
||||||
currentFlagSet.String("sort", "", "Sort listed packages by 'name' or 'size")
|
currentFlagSet.String("sort", "", "Sort listed packages by 'name' or 'size")
|
||||||
currentFlagSet.Bool("reverse", false, "Reverse the order in which packages are listed")
|
currentFlagSet.Bool("reverse", false, "Reverse the order in which packages are listed")
|
||||||
currentFlagSet.BoolP("human-readable", "h", false, "Show package installed size in a human readable format")
|
currentFlagSet.BoolP("show-bytes", "b", false, "Show package installed size in bytes")
|
||||||
setupFlagsAndHelp(currentFlagSet, fmt.Sprintf("bpm %s <options>", subcommand), "List packages", os.Args[2:])
|
setupFlagsAndHelp(currentFlagSet, fmt.Sprintf("bpm %s <options>", subcommand), "List packages", os.Args[2:])
|
||||||
|
|
||||||
showPackageList()
|
showPackageList()
|
||||||
@@ -203,7 +203,7 @@ func showPackageInfo() {
|
|||||||
// Get flags
|
// Get flags
|
||||||
rootDir, _ := currentFlagSet.GetString("root")
|
rootDir, _ := currentFlagSet.GetString("root")
|
||||||
showDatabaseInfo, _ := currentFlagSet.GetBool("database")
|
showDatabaseInfo, _ := currentFlagSet.GetBool("database")
|
||||||
showHumanReadableSize, _ := currentFlagSet.GetBool("human-readable")
|
showBytes, _ := currentFlagSet.GetBool("show-bytes")
|
||||||
|
|
||||||
// Initialize installed packages map
|
// Initialize installed packages map
|
||||||
err := bpmlib.InitializeLocalPackageInformation(rootDir)
|
err := bpmlib.InitializeLocalPackageInformation(rootDir)
|
||||||
@@ -246,7 +246,7 @@ func showPackageInfo() {
|
|||||||
if n != 0 {
|
if n != 0 {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
fmt.Println(entry.CreateReadableInfo(rootDir, showHumanReadableSize))
|
fmt.Println(entry.CreateReadableInfo(rootDir, showBytes))
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -287,7 +287,7 @@ func showPackageInfo() {
|
|||||||
}
|
}
|
||||||
fmt.Println(bpmpkg.PkgInfo.CreateReadableInfo(rootDir))
|
fmt.Println(bpmpkg.PkgInfo.CreateReadableInfo(rootDir))
|
||||||
if bpmpkg.PkgInfo.Type == "binary" {
|
if bpmpkg.PkgInfo.Type == "binary" {
|
||||||
if !showHumanReadableSize {
|
if showBytes {
|
||||||
fmt.Printf("Installed size: %d\n", bpmpkg.GetInstalledSize())
|
fmt.Printf("Installed size: %d\n", bpmpkg.GetInstalledSize())
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Installed size: %s\n", bpmlib.BytesToHumanReadable(bpmpkg.GetInstalledSize()))
|
fmt.Printf("Installed size: %s\n", bpmlib.BytesToHumanReadable(bpmpkg.GetInstalledSize()))
|
||||||
@@ -315,7 +315,7 @@ func showPackageList() {
|
|||||||
showMakeDepends, _ := currentFlagSet.GetBool("make-depends")
|
showMakeDepends, _ := currentFlagSet.GetBool("make-depends")
|
||||||
sortPackages, _ := currentFlagSet.GetString("sort")
|
sortPackages, _ := currentFlagSet.GetString("sort")
|
||||||
reversePackages, _ := currentFlagSet.GetBool("reverse")
|
reversePackages, _ := currentFlagSet.GetBool("reverse")
|
||||||
showHumanReadableSize, _ := currentFlagSet.GetBool("human-readable")
|
showBytes, _ := currentFlagSet.GetBool("show-bytes")
|
||||||
|
|
||||||
if !isFlagSet(currentFlagSet, "manual") && !isFlagSet(currentFlagSet, "depends") && !isFlagSet(currentFlagSet, "make-depends") {
|
if !isFlagSet(currentFlagSet, "manual") && !isFlagSet(currentFlagSet, "depends") && !isFlagSet(currentFlagSet, "make-depends") {
|
||||||
showManual = true
|
showManual = true
|
||||||
@@ -428,7 +428,7 @@ func showPackageList() {
|
|||||||
if n != 0 {
|
if n != 0 {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
fmt.Println(entry.CreateReadableInfo(rootDir, showHumanReadableSize))
|
fmt.Println(entry.CreateReadableInfo(rootDir, showBytes))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if len(installedPackages) == 0 {
|
if len(installedPackages) == 0 {
|
||||||
@@ -453,7 +453,7 @@ func showPackageList() {
|
|||||||
|
|
||||||
fmt.Println(pkg.pkgInfo.CreateReadableInfo(rootDir))
|
fmt.Println(pkg.pkgInfo.CreateReadableInfo(rootDir))
|
||||||
if pkg.pkgInfo.Type == "binary" {
|
if pkg.pkgInfo.Type == "binary" {
|
||||||
if !showHumanReadableSize {
|
if showBytes {
|
||||||
fmt.Printf("Installed size: %d\n", pkg.installedSize)
|
fmt.Printf("Installed size: %d\n", pkg.installedSize)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Installed size: %s\n", bpmlib.BytesToHumanReadable(pkg.installedSize))
|
fmt.Printf("Installed size: %s\n", bpmlib.BytesToHumanReadable(pkg.installedSize))
|
||||||
|
|||||||
@@ -321,7 +321,7 @@ func (entry *BPMDatabaseEntry) GetEntryOptionalDependants() (dependants []string
|
|||||||
return dependants
|
return dependants
|
||||||
}
|
}
|
||||||
|
|
||||||
func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, humanReadableSize bool) string {
|
func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, showBytes bool) string {
|
||||||
builder := strings.Builder{}
|
builder := strings.Builder{}
|
||||||
builderWriteStringNotEmpty := func(label string, value string) {
|
builderWriteStringNotEmpty := func(label string, value string) {
|
||||||
if value != "" {
|
if value != "" {
|
||||||
@@ -457,10 +457,10 @@ func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, humanReadableS
|
|||||||
if entry.Info.Type == "binary" {
|
if entry.Info.Type == "binary" {
|
||||||
installedSize := entry.InstalledSize
|
installedSize := entry.InstalledSize
|
||||||
var installedSizeStr string
|
var installedSizeStr string
|
||||||
if humanReadableSize {
|
if showBytes {
|
||||||
installedSizeStr = BytesToHumanReadable(installedSize)
|
|
||||||
} else {
|
|
||||||
installedSizeStr = strconv.FormatInt(installedSize, 10)
|
installedSizeStr = strconv.FormatInt(installedSize, 10)
|
||||||
|
} else {
|
||||||
|
installedSizeStr = BytesToHumanReadable(installedSize)
|
||||||
}
|
}
|
||||||
builder.WriteString("Installed size: " + installedSizeStr + "\n")
|
builder.WriteString("Installed size: " + installedSizeStr + "\n")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user