forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tesla Command: implement token storage (evcc-io#12021)
- Loading branch information
Showing
6 changed files
with
201 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"regexp" | ||
"syscall" | ||
"text/tabwriter" | ||
|
||
"github.com/evcc-io/evcc/server/db/settings" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// settingsGetCmd represents the configure command | ||
var settingsGetCmd = &cobra.Command{ | ||
Use: "get", | ||
Short: "Get configuration settings", | ||
Run: runSettingsGet, | ||
Args: cobra.MaximumNArgs(1), | ||
} | ||
|
||
func init() { | ||
settingsCmd.AddCommand(settingsGetCmd) | ||
} | ||
|
||
func runSettingsGet(cmd *cobra.Command, args []string) { | ||
// load config | ||
if err := loadConfigFile(&conf); err != nil { | ||
log.FATAL.Fatal(err) | ||
} | ||
|
||
// setup environment | ||
if err := configureEnvironment(cmd, conf); err != nil { | ||
log.FATAL.Fatal(err) | ||
} | ||
|
||
var re *regexp.Regexp | ||
if len(args) > 0 { | ||
re = regexp.MustCompile(args[0]) | ||
} | ||
|
||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0) | ||
for _, s := range settings.All() { | ||
if re != nil && !re.MatchString(s.Key) { | ||
continue | ||
} | ||
|
||
fmt.Fprintf(w, "%s:\t%s\n", s.Key, s.Value) | ||
} | ||
w.Flush() | ||
|
||
// catch signals | ||
go func() { | ||
signalC := make(chan os.Signal, 1) | ||
signal.Notify(signalC, os.Interrupt, syscall.SIGTERM) | ||
|
||
<-signalC // wait for signal | ||
|
||
os.Exit(1) | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// settingsCmd represents the configure command | ||
var settingsCmd = &cobra.Command{ | ||
Use: "settings", | ||
Short: "Manage configuration settings", | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(settingsCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters