Skip to content

Commit a495e59

Browse files
authored
Merge pull request #41 from mJehanno/add-me
feat(me): add me command to get information about the current user
2 parents 6d42e50 + 41bd2dd commit a495e59

File tree

8 files changed

+73
-2
lines changed

8 files changed

+73
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ release-snapshot:
2727
release:
2828
goreleaser release --clean
2929

30-
.PHONY: all wasm doc
30+
.PHONY: all wasm doc

doc/ovhcloud_account.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ Manage your account
3030

3131
* [ovhcloud](ovhcloud.md) - CLI to manage your OVHcloud services
3232
* [ovhcloud account api](ovhcloud_account_api.md) - Manage your API credentials
33+
* [ovhcloud account get](ovhcloud_account_get.md) - Retrieve basic personal information
3334
* [ovhcloud account ssh-key](ovhcloud_account_ssh-key.md) - Manage your SSH keys
3435

doc/ovhcloud_account_get.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## ovhcloud account get
2+
3+
Retrieve basic personal information
4+
5+
```
6+
ovhcloud account get [flags]
7+
```
8+
9+
### Options
10+
11+
```
12+
-h, --help help for get
13+
```
14+
15+
### Options inherited from parent commands
16+
17+
```
18+
-d, --debug Activate debug mode (will log all HTTP requests details)
19+
-f, --format string Output value according to given format (expression using https://github.com/PaesslerAG/gval syntax)
20+
Examples:
21+
--format 'id' (to extract a single field)
22+
--format 'nested.field.subfield' (to extract a nested field)
23+
--format '[id, 'name']' (to extract multiple fields as an array)
24+
--format '{"newKey": oldKey, "otherKey": nested.field}' (to extract and rename fields in an object)
25+
--format 'name+","+type' (to extract and concatenate fields in a string)
26+
--format '(nbFieldA + nbFieldB) * 10' (to compute values from numeric fields)
27+
-e, --ignore-errors Ignore errors in API calls when it is not fatal to the execution
28+
-i, --interactive Interactive output
29+
-j, --json Output in JSON
30+
-y, --yaml Output in YAML
31+
```
32+
33+
### SEE ALSO
34+
35+
* [ovhcloud account](ovhcloud_account.md) - Manage your account
36+

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ require (
2222
github.com/spf13/pflag v1.0.9
2323
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561
2424
golang.org/x/sync v0.16.0
25+
golang.org/x/text v0.27.0
2526
gopkg.in/ini.v1 v1.67.0
2627
)
2728

@@ -69,7 +70,6 @@ require (
6970
golang.org/x/oauth2 v0.30.0 // indirect
7071
golang.org/x/sys v0.34.0 // indirect
7172
golang.org/x/term v0.33.0 // indirect
72-
golang.org/x/text v0.27.0 // indirect
7373
gopkg.in/yaml.v2 v2.4.0 // indirect
7474
gopkg.in/yaml.v3 v3.0.1 // indirect
7575
)

internal/cmd/account.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ func init() {
1616
Short: "Manage your account",
1717
}
1818

19+
accountCmd.AddCommand(&cobra.Command{
20+
Use: "get",
21+
Short: "Retrieve basic personal information",
22+
Run: account.GetMe,
23+
})
24+
1925
// Commands to manage SSH keys
2026
sshKeysCmd := &cobra.Command{
2127
Use: "ssh-key",

internal/display/template.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import (
99
"math"
1010
"strings"
1111
"text/template"
12+
13+
"golang.org/x/text/cases"
14+
"golang.org/x/text/language"
1215
)
1316

1417
var (
@@ -27,6 +30,9 @@ var (
2730
return strings.Join(strElements, ", ")
2831
},
2932
"formatByteSize": formatByteSize,
33+
"toTitle": cases.Title(language.English).String,
34+
"toUpper": strings.ToUpper,
35+
"toLower": strings.ToLower,
3036
}
3137

3238
// unit holds the units for formatting bytes

internal/services/account/account.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ var (
2121
//go:embed parameter-samples/oauth2-client-create.json
2222
Oauth2ClientCreateSample string
2323

24+
//go:embed templates/me.tmpl
25+
meTemplate string
26+
2427
sshKeysColumnsToDisplay = []string{"keyName name", "key"}
2528

2629
Oauth2ClientSpec struct {
@@ -31,6 +34,10 @@ var (
3134
}
3235
)
3336

37+
func GetMe(_ *cobra.Command, _ []string) {
38+
common.ManageObjectRequest("/me", "", meTemplate)
39+
}
40+
3441
func ListSSHKeys(_ *cobra.Command, _ []string) {
3542
common.ManageListRequest("/me/sshKey", "", sshKeysColumnsToDisplay, flags.GenericFilters)
3643
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
👾 Account details
2+
=======
3+
4+
## Contact Information
5+
6+
**Name**: {{index .Result "firstname" | toTitle}} {{index .Result "name" | toUpper}}
7+
**Phone**: {{index .Result "phone" }}
8+
**Email**: {{index .Result "email"}}
9+
10+
## Address
11+
12+
**Street**: {{index .Result "address"}}
13+
**City**: {{index .Result "city"}}
14+
**ZipCode**: {{index .Result "zip"}}
15+
**Country**: {{index .Result "country"}}

0 commit comments

Comments
 (0)