pretty print dolt profile

This commit is contained in:
Stephanie You
2023-08-01 10:19:19 -07:00
parent 1b602743c8
commit 7b8edd2bf1
2 changed files with 23 additions and 5 deletions

View File

@@ -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"`

View File

@@ -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
}