From 5a7995d2268ffdd46f55ee4c34d93e1b07db5572 Mon Sep 17 00:00:00 2001 From: EnumDev Date: Sun, 4 May 2025 17:52:29 +0300 Subject: [PATCH] Move help message and flag setup to bpm-utils-shared package --- src/bpm-package/main.go | 17 +++--------- src/bpm-setup/go.mod | 5 ++++ src/bpm-setup/go.sum | 3 +++ src/bpm-setup/main.go | 51 +++++++++++++----------------------- src/bpm-utils-shared/main.go | 22 ++++++++++++++++ 5 files changed, 51 insertions(+), 47 deletions(-) create mode 100644 src/bpm-setup/go.sum diff --git a/src/bpm-package/main.go b/src/bpm-package/main.go index 04925e0..d31dcab 100644 --- a/src/bpm-package/main.go +++ b/src/bpm-package/main.go @@ -21,8 +21,9 @@ var installPackage = flag.Bool("i", false, "Install compiled BPM package after c var yesAll = flag.Bool("y", false, "Accept all confirmation prompts") func main() { - // Setup flags - setupFlags() + // Setup flags and help + bpmutilsshared.SetupHelp("bpm-package ", "Generates source BPM package from current directory") + bpmutilsshared.SetupFlags() // Run checks runChecks() @@ -35,18 +36,6 @@ func main() { } } -func setupFlags() { - flag.Usage = help - flag.Parse() -} - -func help() { - fmt.Println("Usage: bpm-package ") - fmt.Println("Description: Generates source BPM package from current directory") - fmt.Println("Options:") - flag.PrintDefaults() -} - func runChecks() { // Check if pkg.info file exists if stat, err := os.Stat("pkg.info"); err != nil || !stat.Mode().IsRegular() { diff --git a/src/bpm-setup/go.mod b/src/bpm-setup/go.mod index b4419b4..e630f53 100644 --- a/src/bpm-setup/go.mod +++ b/src/bpm-setup/go.mod @@ -1,3 +1,8 @@ module git.enumerated.dev/bubble-package-manager/bpm-utils/src/bpm-setup go 1.23 + +require bpm-utils-shared v1.0.0 +require gopkg.in/yaml.v3 v3.0.1 // indirect + +replace bpm-utils-shared => ../bpm-utils-shared diff --git a/src/bpm-setup/go.sum b/src/bpm-setup/go.sum new file mode 100644 index 0000000..4bc0337 --- /dev/null +++ b/src/bpm-setup/go.sum @@ -0,0 +1,3 @@ +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/src/bpm-setup/main.go b/src/bpm-setup/main.go index d1ff4c1..defc74a 100644 --- a/src/bpm-setup/main.go +++ b/src/bpm-setup/main.go @@ -1,6 +1,7 @@ package main import ( + bpmutilsshared "bpm-utils-shared" "bufio" "flag" "fmt" @@ -12,25 +13,31 @@ import ( "strings" ) -var directory = flag.String("D", "", "Path to package directory") -var name = flag.String("n", "", "Set the package name (Defaults to \"package-name\")") -var description = flag.String("d", "Default Package Description", "Set the description (Defaults to \"package-description\")") -var version = flag.String("v", "1.0", "Set the package version (Defaults to \"1.0\")") -var url = flag.String("u", "", "Set the package URL (Optional)") -var license = flag.String("l", "", "Set the package licenses (Optional)") -var template = flag.String("t", "gnu-configure", "Set the package template (Defaults to \"gnu-configure\")") -var git = flag.Bool("g", true, "Create git repository (Defaults to true)") +var directory = flag.String("D", "", "Path to package directory (required)") +var name = flag.String("n", "", "Set the package name") +var description = flag.String("d", "Default Package Description", "Set the description") +var version = flag.String("v", "1.0", "Set the package version") +var url = flag.String("u", "", "Set the package URL") +var license = flag.String("l", "", "Set the package licenses") +var template = flag.String("t", "gnu-configure", "Set the package template") +var git = flag.Bool("g", true, "Create git repository") func main() { - // Setup flags - setupFlags() + // Setup flags and help + bpmutilsshared.SetupHelp("bpm-setup ", "Sets up files and directories for BPM source package creation") + bpmutilsshared.SetupFlags() // Show command help if no directory name is given if *directory == "" { - help() + bpmutilsshared.ShowHelp() os.Exit(1) } + // Set package name to directory name if empty + if *name == "" { + *name = filepath.Base(*directory) + } + // run checks runChecks() @@ -50,28 +57,6 @@ func main() { createDirectory() } -func setupFlags() { - flag.Usage = help - flag.Parse() - if *name == "" { - *name = *directory - } -} - -func help() { - fmt.Println("Usage: bpm-setup ") - fmt.Println("Description: bpm-setup sets up directories for BPM source package creation") - fmt.Println("Options:") - fmt.Println(" -D= | Path to package directory") - fmt.Println(" -n= | Set the package name (Defaults to \"package-name\")") - fmt.Println(" -d= | Set the package description (Defaults to \"Default package description\")") - fmt.Println(" -v= | Set the package version (Defaults to \"1.0\")") - fmt.Println(" -u= | Set the package URL (Optional)") - fmt.Println(" -l= | Set the package licenses (Optional)") - fmt.Println(" -t=