Skip to content

Commit

Permalink
feat: show update and issue informations #63
Browse files Browse the repository at this point in the history
  • Loading branch information
leukipp committed Aug 13, 2024
1 parent 295c97a commit cffb493
Show file tree
Hide file tree
Showing 14 changed files with 504 additions and 216 deletions.
45 changes: 26 additions & 19 deletions common/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ var (
)

type Arguments struct {
Cache string // Argument for cache folder path
Config string // Argument for config file path
Lock string // Argument for lock file path
Log string // Argument for log file path
VVV bool // Argument for very very verbose mode
VV bool // Argument for very verbose mode
V bool // Argument for verbose mode
Cache string // Argument for cache folder path
Config string // Argument for config file path
Lock string // Argument for lock file path
Log string // Argument for log file path
VVV bool // Argument for very very verbose mode
VV bool // Argument for very verbose mode
V bool // Argument for verbose mode
P []string // Argument for positional values
Dbus struct {
Listen bool // Argument for dbus listen flag
Method string // Argument for dbus method name
Property string // Argument for dbus property name
Args []string // Argument for dbus method arguments
P []string // Argument for dbus positional values
}
}

Expand All @@ -38,25 +39,30 @@ func InitArgs(introspect map[string][]string) {
flag.BoolVar(&Args.VVV, "vvv", false, "very very verbose mode")
flag.BoolVar(&Args.VV, "vv", false, "very verbose mode")
flag.BoolVar(&Args.V, "v", false, "verbose mode")
Args.P = []string{}

// Command line usage text
flag.CommandLine.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "%s\n\nUsage:\n", Build.Summary)
flag.PrintDefaults()
}

// Parse command line arguments
flag.Parse()
Args.P = flag.Args()

// Subcommand line arguments
dbus := flag.NewFlagSet("dbus", flag.ExitOnError)
dbus.BoolVar(&Args.Dbus.Listen, "listen", false, "dbus listen mode")
dbus.StringVar(&Args.Dbus.Method, "method", "", "dbus method caller")
dbus.StringVar(&Args.Dbus.Property, "property", "", "dbus property reader")
Args.Dbus.Args = []string{}
Args.Dbus.P = []string{}

// Subcommand line usage text
if len(os.Args) > 1 {
switch os.Args[1] {
case "dbus":

// Subcommand line usage text
dbus.Usage = func() {
fmt.Fprintf(dbus.Output(), "%s\n\nUsage:\n", Build.Summary)
dbus.PrintDefaults()
Expand All @@ -78,18 +84,21 @@ func InitArgs(introspect map[string][]string) {
fmt.Fprintf(dbus.Output(), "\n>>> start %s to see further information's <<<\n", Build.Name)
}
}
Args.Dbus.Args = ParseArgs(dbus, os.Args[2:])
}

// Check number of arguments
if flag.NArg() == 1 {
dbus.Usage()
os.Exit(1)
// Parse subcommand line arguments
FlagParse(dbus, os.Args[2:])
Args.Dbus.P = dbus.Args()

// Check subcommand line arguments
if !Args.Dbus.Listen && len(Args.Dbus.Method) == 0 && len(Args.Dbus.Property) == 0 {
dbus.Usage()
os.Exit(1)
}
}
}
}

func ParseArgs(flags *flag.FlagSet, args []string) []string {
func FlagParse(flags *flag.FlagSet, args []string) {
pargs := []string{}

for {
Expand All @@ -109,6 +118,4 @@ func ParseArgs(flags *flag.FlagSet, args []string) []string {

// Parse positional arguments
flags.Parse(pargs)

return flags.Args()
}
6 changes: 3 additions & 3 deletions common/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Cache[T any] struct {
}

func InitCache() {
if !CacheEnabled() {
if CacheDisabled() {
return
}

Expand All @@ -38,7 +38,7 @@ func CacheFolderPath(name string) string {
return filepath.Join(userCacheDir, name)
}

func CacheEnabled() bool {
func CacheDisabled() bool {
arg := strings.ToLower(strings.TrimSpace(Args.Cache))
return !IsInList(arg, []string{"", "0", "off", "false", "disabled"})
return HasFlag("disable-cache-folder") || IsInList(arg, []string{"", "0", "off", "false", "disabled"})
}
11 changes: 6 additions & 5 deletions common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func InitConfig() {
// Read config file into memory
readConfig(Args.Config)

// Config file watcher
// Config file system watcher
watchConfig(Args.Config)
}

Expand All @@ -73,7 +73,11 @@ func ConfigFolderPath(name string) string {
func readConfig(configFilePath string) {

// Print build infos
fmt.Printf("BUILD: \n name: %s\n version: v%s-%s\n date: %s\n\n", Build.Name, Build.Version, Build.Commit, Build.Date)
fmt.Print("BUILD")
if HasReleaseInfos() {
fmt.Printf(" [>>> %s v%s is available <<<]", Build.Name, Source.Releases[0].Name)
}
fmt.Printf(": \n name: %s\n version: v%s-%s\n date: %s\n\n", Build.Name, Build.Version, Build.Commit, Build.Date)

// Print file infos
fmt.Printf("FILES: \n log: %s\n lock: %s\n cache: %s\n config: %s\n\n", Args.Log, Args.Lock, Args.Cache, configFilePath)
Expand All @@ -89,9 +93,6 @@ func readConfig(configFilePath string) {
fmt.Printf("KEYS: %s\n", RemoveChars(string(keys), []string{"{", "}", "\"", ","}))
fmt.Printf("CORNERS: %s\n", RemoveChars(string(corners), []string{"{", "}", "\"", ","}))
fmt.Printf("SYSTRAY: %s\n", RemoveChars(string(systray), []string{"{", "}", "\"", ","}))

// Log startup infos
log.Info("Starting [", Build.Summary, "]")
}

func watchConfig(configFilePath string) {
Expand Down
6 changes: 3 additions & 3 deletions common/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ var (

type FileData struct {
Toml []byte // Default config file
Icon []byte // Application icon
Logo []byte // Application logo icon
}

func InitFiles(toml, icon []byte) {
func InitFiles(toml, logo []byte) {

// Init embedded files
File = FileData{
Toml: toml,
Icon: icon,
Logo: logo,
}
}
Loading

0 comments on commit cffb493

Please sign in to comment.