|
@@ -3,28 +3,21 @@ package cmd
|
|
|
import (
|
|
import (
|
|
|
"errors"
|
|
"errors"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
- "github.com/urfave/cli/v2"
|
|
|
|
|
- "heckel.io/ntfy/v2/client"
|
|
|
|
|
- "heckel.io/ntfy/v2/log"
|
|
|
|
|
- "heckel.io/ntfy/v2/util"
|
|
|
|
|
"os"
|
|
"os"
|
|
|
"os/exec"
|
|
"os/exec"
|
|
|
- "os/user"
|
|
|
|
|
- "path/filepath"
|
|
|
|
|
"sort"
|
|
"sort"
|
|
|
"strings"
|
|
"strings"
|
|
|
|
|
+
|
|
|
|
|
+ "github.com/urfave/cli/v2"
|
|
|
|
|
+ "heckel.io/ntfy/v2/client"
|
|
|
|
|
+ "heckel.io/ntfy/v2/log"
|
|
|
|
|
+ "heckel.io/ntfy/v2/util"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
func init() {
|
|
|
commands = append(commands, cmdSubscribe)
|
|
commands = append(commands, cmdSubscribe)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const (
|
|
|
|
|
- clientRootConfigFileUnixAbsolute = "/etc/ntfy/client.yml"
|
|
|
|
|
- clientUserConfigFileUnixRelative = "ntfy/client.yml"
|
|
|
|
|
- clientUserConfigFileWindowsRelative = "ntfy\\client.yml"
|
|
|
|
|
-)
|
|
|
|
|
-
|
|
|
|
|
var flagsSubscribe = append(
|
|
var flagsSubscribe = append(
|
|
|
append([]cli.Flag{}, flagsDefault...),
|
|
append([]cli.Flag{}, flagsDefault...),
|
|
|
&cli.StringFlag{Name: "config", Aliases: []string{"c"}, Usage: "client config file"},
|
|
&cli.StringFlag{Name: "config", Aliases: []string{"c"}, Usage: "client config file"},
|
|
@@ -310,45 +303,16 @@ func loadConfig(c *cli.Context) (*client.Config, error) {
|
|
|
if filename != "" {
|
|
if filename != "" {
|
|
|
return client.LoadConfig(filename)
|
|
return client.LoadConfig(filename)
|
|
|
}
|
|
}
|
|
|
- configFile, err := defaultClientConfigFile()
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- log.Warn("Could not determine default client config file: %s", err.Error())
|
|
|
|
|
- } else {
|
|
|
|
|
- if s, _ := os.Stat(configFile); s != nil {
|
|
|
|
|
- return client.LoadConfig(configFile)
|
|
|
|
|
|
|
+ if client.DefaultConfigFile != "" {
|
|
|
|
|
+ if s, _ := os.Stat(client.DefaultConfigFile); s != nil {
|
|
|
|
|
+ return client.LoadConfig(client.DefaultConfigFile)
|
|
|
}
|
|
}
|
|
|
- log.Debug("Config file %s not found", configFile)
|
|
|
|
|
|
|
+ log.Debug("Config file %s not found", client.DefaultConfigFile)
|
|
|
}
|
|
}
|
|
|
log.Debug("Loading default config")
|
|
log.Debug("Loading default config")
|
|
|
return client.NewConfig(), nil
|
|
return client.NewConfig(), nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-//lint:ignore U1000 Conditionally used in different builds
|
|
|
|
|
-func defaultClientConfigFileUnix() (string, error) {
|
|
|
|
|
- u, err := user.Current()
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return "", fmt.Errorf("could not determine current user: %w", err)
|
|
|
|
|
- }
|
|
|
|
|
- configFile := clientRootConfigFileUnixAbsolute
|
|
|
|
|
- if u.Uid != "0" {
|
|
|
|
|
- homeDir, err := os.UserConfigDir()
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return "", fmt.Errorf("could not determine user config dir: %w", err)
|
|
|
|
|
- }
|
|
|
|
|
- return filepath.Join(homeDir, clientUserConfigFileUnixRelative), nil
|
|
|
|
|
- }
|
|
|
|
|
- return configFile, nil
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-//lint:ignore U1000 Conditionally used in different builds
|
|
|
|
|
-func defaultClientConfigFileWindows() (string, error) {
|
|
|
|
|
- homeDir, err := os.UserConfigDir()
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return "", fmt.Errorf("could not determine user config dir: %w", err)
|
|
|
|
|
- }
|
|
|
|
|
- return filepath.Join(homeDir, clientUserConfigFileWindowsRelative), nil
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
func logMessagePrefix(m *client.Message) string {
|
|
func logMessagePrefix(m *client.Message) string {
|
|
|
return fmt.Sprintf("%s/%s", util.ShortTopicURL(m.TopicURL), m.ID)
|
|
return fmt.Sprintf("%s/%s", util.ShortTopicURL(m.TopicURL), m.ID)
|
|
|
}
|
|
}
|