Skip to content

Commit 21c98b0

Browse files
committed
✨ feat(columns): + to add columns to output
1 parent e4f5c4e commit 21c98b0

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ octl <command> <command>
140140
| `--config` | `~/.osc/config.json` | | config file path |
141141
| `--profile` | `default` | | profile name |
142142
| `--output` | | `raw`, `json`, `yaml`, `table` | output format |
143-
| `--columns` | | | columns to display in a table (`title:field,title:field`) |
143+
| `--columns` | | | columns to display in a table |
144144

145145
### Output formats
146146

@@ -183,9 +183,9 @@ VolumeId: vol-foo
183183
VolumeType: io1
184184
```
185185

186-
Columns can be changed:
186+
Columns can be replaced:
187187
```shell
188-
octl iaas vm list --columns ID:VmId,DNS:PrivateDnsName
188+
octl iaas vm list --columns "ID:VmId|DNS:PrivateDnsName"
189189
┌────────────┬───────────────────────────────────────────┐
190190
│ ID │ DNS │
191191
├────────────┼───────────────────────────────────────────┤
@@ -195,6 +195,17 @@ octl iaas vm list --columns ID:VmId,DNS:PrivateDnsName
195195
└────────────┴───────────────────────────────────────────┘
196196
```
197197

198+
Columns can be added to the standard columns:
199+
```shell
200+
octl iaas vm list --columns +DNS:PrivateDnsName
201+
```
202+
203+
Column content is defined with the [expr language](https://expr-lang.org/docs/language-definition). To display a tag value:
204+
```shell
205+
octl iaas vm list --columns "+tag:find(Tags, #?.Key == \"Name\")?.Value"
206+
```
207+
208+
198209
### API access
199210

200211
The API can be directly called, with a `raw` output:

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func init() {
7474
rootCmd.PersistentFlags().String("config", "", fmt.Sprintf("Path of profile file (by default, %q)", path))
7575
rootCmd.PersistentFlags().String("profile", "", fmt.Sprintf("Profile to use in profile file (by default, %q)", profile.DefaultProfile))
7676
rootCmd.PersistentFlags().String("template", "", "JSON template for query body")
77-
rootCmd.PersistentFlags().StringP("columns", "c", "", "columns to display")
77+
rootCmd.PersistentFlags().StringP("columns", "c", "", "columns to display - [+]title:content|title:content")
7878
rootCmd.PersistentFlags().StringP("output", "o", "", "output format (raw, json, yaml, table, none)")
7979
rootCmd.PersistentFlags().Bool("no-upgrade", false, "do not check for new versions")
8080
rootCmd.PersistentFlags().BoolP("yes", "y", false, "answer yes to all prompts")

pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (c *Column) Get(v any) (any, error) {
4545
type Columns []Column
4646

4747
func ParseColumns(s string) Columns {
48-
ss := strings.Split(s, ",")
48+
ss := strings.Split(s, "|")
4949
cs := make(Columns, 0, len(ss))
5050
for _, s := range ss {
5151
title, content, found := strings.Cut(s, ":")

pkg/output/flags.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ func NewFromFlags(fs *pflag.FlagSet, c config.Call, e config.Entity) (Output, er
3030
var cols config.Columns
3131
fcols, _ := fs.GetString("columns")
3232
if fcols != "" {
33-
cols = config.ParseColumns(fcols)
33+
add := strings.HasPrefix(fcols, "+")
34+
pfcols := config.ParseColumns(strings.TrimPrefix(fcols, "+"))
35+
if add {
36+
cols = append(slices.Clone(e.Columns), pfcols...)
37+
} else {
38+
cols = pfcols
39+
}
3440
} else {
3541
cols = slices.Clone(e.Columns)
3642
}

0 commit comments

Comments
 (0)