add flag for Mediatype: media, video, lofi
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 9s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 9s
This commit is contained in:
@@ -38,6 +38,7 @@ func init() {
|
||||
exportCmd.Flags().StringVarP(&config.ServerName, "servername", "s", "local", "Define server to get Kontor items")
|
||||
updateTitleCmd.Flags().StringVarP(&config.ServerName, "servername", "s", "local", "Define server to get Kontor items")
|
||||
addLinksCmd.Flags().StringVarP(&config.ServerName, "servername", "s", "local", "Define server to get Kontor items")
|
||||
addLinksCmd.Flags().Var(&config.Mediatype, "mediatype", "MediaType: allowed values are: media, videos, lofi")
|
||||
viper.BindPFlag("server", exportCmd.PersistentFlags().Lookup("server"))
|
||||
cobra.OnInitialize(config.InitCliConfig)
|
||||
}
|
||||
|
||||
@@ -1,18 +1,55 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type MediaType string
|
||||
|
||||
const (
|
||||
mediaTypeMedia MediaType = "media"
|
||||
mediaTypeVideo MediaType = "video"
|
||||
mediaTypeLofi MediaType = "lofi"
|
||||
)
|
||||
|
||||
func (e *MediaType) String() string {
|
||||
return string(*e)
|
||||
}
|
||||
|
||||
func (e *MediaType) Set(v string) error {
|
||||
switch v {
|
||||
case "media", "video", "lofi":
|
||||
*e = MediaType(v)
|
||||
return nil
|
||||
default:
|
||||
return errors.New(`must be one of "media", "video", "lofi"`)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *MediaType) Type() string {
|
||||
return "MediaType"
|
||||
}
|
||||
|
||||
func myEnumCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return []string{
|
||||
"media\thelp text for media",
|
||||
"video\thelp text for video",
|
||||
"lofi\thelp text for lofi",
|
||||
}, cobra.ShellCompDirectiveDefault
|
||||
}
|
||||
|
||||
var (
|
||||
CfgFile string
|
||||
Verbose int
|
||||
Overwrite bool
|
||||
ServerName string
|
||||
Mediatype MediaType
|
||||
Config CliConfig
|
||||
DryRun bool
|
||||
)
|
||||
@@ -38,6 +75,7 @@ func InitCliConfig() {
|
||||
viper.AddConfigPath(".") // look for config in working directory
|
||||
viper.AddConfigPath("/home/tpeetz/.config")
|
||||
}
|
||||
Mediatype = mediaTypeMedia
|
||||
|
||||
// Read the configuration file
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user