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` |
|
| token | an application token (a client token will not work) | `A4ZudDRdLT40L5X` |
|
||||||
| url | the URL to your [gotify/server][gotify/server] | `https://gotify.example.com` |
|
| 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
|
### Config example
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"token": "A4ZudDRdLT40L5X",
|
"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("Used Config:", conf.FromLocation)
|
||||||
fmt.Println("URL:", conf.URL)
|
fmt.Println("URL:", conf.URL)
|
||||||
|
fmt.Println("Default Priority:", conf.DefaultPriority)
|
||||||
fmt.Println("Token:", conf.Token)
|
fmt.Println("Token:", conf.Token)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,10 +35,13 @@ func doInit(ctx *cli.Context) {
|
|||||||
hr()
|
hr()
|
||||||
token := inputToken(gotify.NewClient(serverURL, utils.CreateHTTPClient()))
|
token := inputToken(gotify.NewClient(serverURL, utils.CreateHTTPClient()))
|
||||||
hr()
|
hr()
|
||||||
|
defaultPriority := inputDefaultPriority()
|
||||||
|
hr()
|
||||||
|
|
||||||
conf := &config.Config{
|
conf := &config.Config{
|
||||||
URL: serverURL.String(),
|
URL: serverURL.String(),
|
||||||
Token: token,
|
Token: token,
|
||||||
|
DefaultPriority: defaultPriority,
|
||||||
}
|
}
|
||||||
|
|
||||||
pathToWrite, err := config.ExistingConfig(config.GetLocations())
|
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 {
|
func inputServerURL() *url.URL {
|
||||||
for {
|
for {
|
||||||
rawURL := inputString("Gotify URL: ")
|
rawURL := inputString("Gotify URL: ")
|
||||||
|
|||||||
@@ -64,6 +64,10 @@ func doPush(ctx *cli.Context) {
|
|||||||
stringURL = conf.URL
|
stringURL = conf.URL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !ctx.IsSet("priority") {
|
||||||
|
priority = conf.DefaultPriority
|
||||||
|
}
|
||||||
|
|
||||||
msg := models.MessageExternal{
|
msg := models.MessageExternal{
|
||||||
Message: msgText,
|
Message: msgText,
|
||||||
Title: title,
|
Title: title,
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
FromLocation string `json:"-"`
|
DefaultPriority int `json:"defaultPriority"`
|
||||||
|
FromLocation string `json:"-"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user