From 7b8edd2bf1cb23cbdf96cca96c56fdc64db2644a Mon Sep 17 00:00:00 2001 From: Stephanie You Date: Tue, 1 Aug 2023 10:19:19 -0700 Subject: [PATCH] pretty print dolt profile --- go/cmd/dolt/commands/profile.go | 18 ++++++++++++++++-- integration-tests/bats/profile.bats | 10 +++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/go/cmd/dolt/commands/profile.go b/go/cmd/dolt/commands/profile.go index a4d1e5b84b..3893747886 100644 --- a/go/cmd/dolt/commands/profile.go +++ b/go/cmd/dolt/commands/profile.go @@ -17,6 +17,8 @@ package commands import ( "context" "encoding/json" + "fmt" + "os" "strings" "github.com/tidwall/gjson" @@ -143,6 +145,8 @@ func addProfile(dEnv *env.DoltEnv, apr *argparser.ArgParseResults) errhand.Verbo if err != nil { return errhand.BuildDError("error: failed to set profiles").Build() } + path := "~/.dolt/config_global.json" + err = os.Chmod(path, 0400) return nil } @@ -202,13 +206,23 @@ func printProfiles(dEnv *env.DoltEnv) errhand.VerboseError { } for profileName, profile := range profileMap.Map() { - cli.Println(profileName + ":") - cli.Println(profile) + var p Profile + var val []byte = []byte(profile.String()) + err := json.Unmarshal([]byte(val), &p) + if err != nil { + return errhand.BuildDError("error: failed to unmarshal profile").Build() + } + prettyPrintProfile(profileName, p) } return nil } +func prettyPrintProfile(profileName string, profile Profile) { + cli.Println(fmt.Sprintf("%s:\n\tuser: %s\n\tpassword: %s\n\thost: %s\n\tport: %s\n\tno-tls: %t\n\tdata-dir: %s\n\tdoltcfg-dir: %s\n\tprivilege-file: %s\n\tbranch-control-file: %s\n\tuse-db: %s\n", + profileName, profile.User, profile.Password, profile.Host, profile.Port, profile.NoTLS, profile.DataDir, profile.DoltCfgDir, profile.PrivilegeFile, profile.BranchControl, profile.UseDB)) +} + type Profile struct { User string `json:"user"` Password string `json:"password"` diff --git a/integration-tests/bats/profile.bats b/integration-tests/bats/profile.bats index 047454d004..92af55e5be 100755 --- a/integration-tests/bats/profile.bats +++ b/integration-tests/bats/profile.bats @@ -244,10 +244,14 @@ teardown() { @test "profile: dolt profile lists all profiles" { dolt profile add --use-db altDB altTest - dolt profile add --use-db defaultDB defaultTest + dolt profile add --use-db defaultDB -u "steph" --password "pass" defaultTest run dolt profile [ "$status" -eq 0 ] || false - [[ "$output" =~ "altTest" ]] || false - [[ "$output" =~ "defaultTest" ]] || false + [[ "$output" =~ "altTest:" ]] || false + [[ "$output" =~ "use-db: altDB" ]] || false + [[ "$output" =~ "defaultTest:" ]] || false + [[ "$output" =~ "user: steph" ]] || false + [[ "$output" =~ "password: pass" ]] || false + [[ "$output" =~ "use-db: defaultDB" ]] || false }