Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cli new config updates #93

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cmd/tesla-http-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ func main() {
host string
port int
)
config := cli.Config{Flags: cli.FlagPrivateKey}
var err error

config, err := cli.NewConfig(cli.FlagPrivateKey)

if err != nil {
fmt.Fprintf(os.Stderr, "Failed to load credential configuration: %s\n", err)
os.Exit(1)
}

defer func() {
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
Expand Down
13 changes: 8 additions & 5 deletions pkg/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ and OAuth tokens) in an OS-dependent credential store.

import flag

config := Config{Flags: FlagAll}
config, err := NewConfig(FlagAll)
if err != nil {
panic(err)
}
config.RegisterCommandLineFlags() // Adds command-line flags for private keys, OAuth, etc.
flag.Parse()
config.ReadFromEnvironment() // Fills in missing fields using environment variables
Expand All @@ -34,13 +37,13 @@ Alternatively, you can use a [Flag] mask to control what [Config] fields are pop
the examples below, config.Flags must be set before calling [flag.Parse] or
[Config.ReadFromEnvironment]:

config = Config{Flags: FlagOAuth | FlagPrivateKey | FlagVIN} // config.Connect() will use the Internet, not BLE.
config = Config{Flags: FlagBLE | FlagPrivateKey | FlagVIN} // config.Connect() will use BLE, not the Internet.
config = Config{Flags: FlagBLE | FlagVIN} // config.Connect() will create an unauthenticated vehicle connection.
config, err = NewConfig(FlagOAuth | FlagPrivateKey | FlagVIN) // config.Connect() will use the Internet, not BLE.
config, err = NewConfig(FlagBLE | FlagPrivateKey | FlagVIN) // config.Connect() will use BLE, not the Internet.
config, err = NewConfig(FlagBLE | FlagVIN) // config.Connect() will create an unauthenticated vehicle connection.

The last option will not attempt to load private keys when calling [Config.Connect], and therefore
will not result in an error if a private key is defined in the environment but cannot be loaded.
However, most [vehicle.Vehicle] commands do not work over unauathenticated connections.
However, most [vehicle.Vehicle] commands do not work over unauthenticated connections.
*/
package cli

Expand Down