62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"flag"
|
|
"fmt"
|
|
"io/ioutil"
|
|
)
|
|
|
|
type App struct {
|
|
Name string `json:"name"`
|
|
Shortcuts map[string]string `json:"shortcuts"`
|
|
}
|
|
|
|
type Config struct {
|
|
Apps []App `json:"apps"`
|
|
}
|
|
|
|
func main() {
|
|
|
|
flag.Usage = func() {
|
|
fmt.Println("")
|
|
fmt.Println("- -- - -- - -- - -- - -- - -- - -- - --")
|
|
fmt.Println("Scut-Reminder : Gestion des raccourcis")
|
|
fmt.Println("- -- - -- - -- - -- - -- - -- - -- - --")
|
|
fmt.Println("Options :")
|
|
fmt.Printf(" -c NomDuFichierConfig Utiliser ce fichier de configuration au lieu de config.json (par défaut)\n")
|
|
fmt.Printf(" -a Nom Application Afficher les raccourcis de l'application spécifiée\n")
|
|
fmt.Printf(" -h Afficher cette aide\n")
|
|
fmt.Println("")
|
|
fmt.Println("Example :")
|
|
fmt.Printf(" scut // Affiche la liste des applications\n\n")
|
|
fmt.Printf(" scut -c MaConfig.json -a \"nevim\" // Affiche liste des raccourcis de nevim de MaConfig.json \n\n")
|
|
fmt.Printf(" scut -a \"Visual Studio Code\" //Affiche liste des raccourcis de vscode \n\n")
|
|
fmt.Println("")
|
|
}
|
|
|
|
configFile := flag.String("c", "config.json", "Config file")
|
|
appName := flag.String("a", "", "Application name")
|
|
flag.Parse()
|
|
|
|
data, _ := ioutil.ReadFile(*configFile)
|
|
var config Config
|
|
json.Unmarshal(data, &config)
|
|
|
|
if *appName == "" {
|
|
// List all applications
|
|
for _, app := range config.Apps {
|
|
fmt.Printf("%s\n", app.Name)
|
|
}
|
|
} else {
|
|
// List shortcuts for application
|
|
for _, app := range config.Apps {
|
|
if app.Name == *appName {
|
|
for shortcut, desc := range app.Shortcuts {
|
|
fmt.Printf("%s: %s\n", shortcut, desc)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|