mirror of
https://github.com/gotify/cli.git
synced 2024-01-28 15:20:39 +03:00
Add ability to set a default priority for cli client, fix #2
This commit is contained in:
committed by
Jannis Mattheis
parent
facfb9b517
commit
a38bf37dcd
@@ -151,13 +151,15 @@ Gotify-CLI will search the following paths for a config file:
|
||||
| ----- | ----------- | ------- |
|
||||
| token | an application token (a client token will not work) | `A4ZudDRdLT40L5X` |
|
||||
| url | the URL to your [gotify/server][gotify/server] | `https://gotify.example.com` |
|
||||
| defaultPriority | Default priority ( set to 0 if not present) | `6` |
|
||||
|
||||
### Config example
|
||||
|
||||
```json
|
||||
{
|
||||
"token": "A4ZudDRdLT40L5X",
|
||||
"url": "https://gotify.example.com"
|
||||
"url": "https://gotify.example.com",
|
||||
"defaultPriority": 6
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ func Config() cli.Command {
|
||||
}
|
||||
fmt.Println("Used Config:", conf.FromLocation)
|
||||
fmt.Println("URL:", conf.URL)
|
||||
fmt.Println("Default Priority:", conf.DefaultPriority)
|
||||
fmt.Println("Token:", conf.Token)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -35,10 +35,13 @@ func doInit(ctx *cli.Context) {
|
||||
hr()
|
||||
token := inputToken(gotify.NewClient(serverURL, utils.CreateHTTPClient()))
|
||||
hr()
|
||||
defaultPriority := inputDefaultPriority()
|
||||
hr()
|
||||
|
||||
conf := &config.Config{
|
||||
URL: serverURL.String(),
|
||||
Token: token,
|
||||
DefaultPriority: defaultPriority,
|
||||
}
|
||||
|
||||
pathToWrite, err := config.ExistingConfig(config.GetLocations())
|
||||
@@ -204,6 +207,20 @@ func inputRawToken(gotify *api.GotifyREST) string {
|
||||
|
||||
}
|
||||
|
||||
func inputDefaultPriority() int {
|
||||
for {
|
||||
defaultPriorityStr := inputString("Default Priority [0-10]: ")
|
||||
defaultPriority, err := strconv.Atoi(defaultPriorityStr)
|
||||
if err != nil || (defaultPriority > 10 || defaultPriority < 0) {
|
||||
erred("Priority needs to be a number between 0 and 10.")
|
||||
continue
|
||||
} else {
|
||||
return defaultPriority
|
||||
}
|
||||
hr()
|
||||
}
|
||||
}
|
||||
|
||||
func inputServerURL() *url.URL {
|
||||
for {
|
||||
rawURL := inputString("Gotify URL: ")
|
||||
|
||||
@@ -64,6 +64,10 @@ func doPush(ctx *cli.Context) {
|
||||
stringURL = conf.URL
|
||||
}
|
||||
|
||||
if !ctx.IsSet("priority") {
|
||||
priority = conf.DefaultPriority
|
||||
}
|
||||
|
||||
msg := models.MessageExternal{
|
||||
Message: msgText,
|
||||
Title: title,
|
||||
|
||||
@@ -3,5 +3,6 @@ package config
|
||||
type Config struct {
|
||||
Token string `json:"token"`
|
||||
URL string `json:"url"`
|
||||
DefaultPriority int `json:"defaultPriority"`
|
||||
FromLocation string `json:"-"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user