Skip to content

Commit

Permalink
feat(cli): support json format for get and invoke
Browse files Browse the repository at this point in the history
Also improves error handling and reporting.

Signed-off-by: Brian McGee <[email protected]>
  • Loading branch information
brianmcgee committed Apr 15, 2024
1 parent 713b26e commit 5bfcb11
Show file tree
Hide file tree
Showing 9 changed files with 366 additions and 83 deletions.
98 changes: 87 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,48 @@ some methods.

```terminal
❯ nix run .# -- invoke org.freedesktop.systemd1 /org/freedesktop/systemd1 GetDefaultTarget
NKey: UAMLBE4LIDYXH6FO5LW6CPLEBZJ23I2OT3TPZYIJPQY5HJ46X3BU7UJK
[default.target]
NKey: UBQUIKYGFC7CH5XMF52P2NN4ESI4XTXGAKT3WTG3XGU3352DMHGZQAX7
["default.target"]
[default.target]
NKey: UAILZJS66U24VALTH2D6OWVD5JTS3IDFMKOICJSOX7CHNAF3AXFVWIFX
["default.target"]
[default.target]
NKey: UAMLBE4LIDYXH6FO5LW6CPLEBZJ23I2OT3TPZYIJPQY5HJ46X3BU7UJK
```

["default.target"]
JSON output with `-J` flag:

```terminal
❯ nix run .# -- invoke org.freedesktop.systemd1 /org/freedesktop/systemd1 GetDefaultTarget -J | jq
{
"destination": "org.freedesktop.systemd1",
"path": "/org/freedesktop/systemd1",
"responses": [
{
"nkey": "UBQUIKYGFC7CH5XMF52P2NN4ESI4XTXGAKT3WTG3XGU3352DMHGZQAX7",
"value": [
"default.target"
]
},
{
"nkey": "UAMLBE4LIDYXH6FO5LW6CPLEBZJ23I2OT3TPZYIJPQY5HJ46X3BU7UJK",
"value": [
"default.target"
]
},
{
"nkey": "UAILZJS66U24VALTH2D6OWVD5JTS3IDFMKOICJSOX7CHNAF3AXFVWIFX",
"value": [
"default.target"
]
}
]
}
```

#### Get a property on all machines
Expand All @@ -109,17 +140,42 @@ NKey: UAMLBE4LIDYXH6FO5LW6CPLEBZJ23I2OT3TPZYIJPQY5HJ46X3BU7UJK
NKey: UBQUIKYGFC7CH5XMF52P2NN4ESI4XTXGAKT3WTG3XGU3352DMHGZQAX7
Signature: s
"active"
active
NKey: UAMLBE4LIDYXH6FO5LW6CPLEBZJ23I2OT3TPZYIJPQY5HJ46X3BU7UJK
NKey: UAILZJS66U24VALTH2D6OWVD5JTS3IDFMKOICJSOX7CHNAF3AXFVWIFX
Signature: s
"active"
active
NKey: UAILZJS66U24VALTH2D6OWVD5JTS3IDFMKOICJSOX7CHNAF3AXFVWIFX
NKey: UAMLBE4LIDYXH6FO5LW6CPLEBZJ23I2OT3TPZYIJPQY5HJ46X3BU7UJK
Signature: s
"active"
active
```

JSON output with `-J` flag:

```terminal
❯ nix run .# -- get org.freedesktop.systemd1 /org/freedesktop/systemd1/unit/basic_2etarget ActiveState -J | jq
{
"destination": "org.freedesktop.systemd1",
"path": "/org/freedesktop/systemd1/unit/basic_2etarget",
"responses": [
{
"nkey": "UAILZJS66U24VALTH2D6OWVD5JTS3IDFMKOICJSOX7CHNAF3AXFVWIFX",
"value": "active"
},
{
"nkey": "UBQUIKYGFC7CH5XMF52P2NN4ESI4XTXGAKT3WTG3XGU3352DMHGZQAX7",
"value": "active"
},
{
"nkey": "UAMLBE4LIDYXH6FO5LW6CPLEBZJ23I2OT3TPZYIJPQY5HJ46X3BU7UJK",
"value": "active"
}
]
}
```

#### Get a property on a list of machines by NATS NKey
Expand All @@ -129,12 +185,32 @@ Signature: s
Signature: s
NKey: UAMLBE4LIDYXH6FO5LW6CPLEBZJ23I2OT3TPZYIJPQY5HJ46X3BU7UJK
"active"
active
NKey: UBQUIKYGFC7CH5XMF52P2NN4ESI4XTXGAKT3WTG3XGU3352DMHGZQAX7
Signature: s
"active"
active
```

JSON output with `-J` flag:

```terminal
❯ nix run .# -- get org.freedesktop.systemd1 /org/freedesktop/systemd1/unit/basic_2etarget ActiveState --nkeys UBQUIKYGFC7CH5XMF52P2NN4ESI4XTXGAKT3WTG3XGU3352DMHGZQAX7,UAMLBE4LIDYXH6FO5LW6CPLEBZJ23I2OT3TPZYIJPQY5HJ46X3BU7UJK -J | jq
{
"destination": "org.freedesktop.systemd1",
"path": "/org/freedesktop/systemd1/unit/basic_2etarget",
"responses": [
{
"nkey": "UBQUIKYGFC7CH5XMF52P2NN4ESI4XTXGAKT3WTG3XGU3352DMHGZQAX7",
"value": "active"
},
{
"nkey": "UAMLBE4LIDYXH6FO5LW6CPLEBZJ23I2OT3TPZYIJPQY5HJ46X3BU7UJK",
"value": "active"
}
]
}
```

#### Listen for all signals from each machine
Expand Down
32 changes: 21 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ require (
github.com/charmbracelet/log v0.4.0
github.com/godbus/dbus/v5 v5.1.0
github.com/juju/errors v1.0.0
github.com/nats-io/nats.go v1.33.1
github.com/nats-io/nats.go v1.34.1
github.com/numtide/nits v0.0.0-20240315145428-585ec33b9d48
github.com/ztrue/shutdown v0.1.1
golang.org/x/crypto v0.21.0
golang.org/x/sync v0.6.0
golang.org/x/crypto v0.22.0
golang.org/x/sync v0.7.0
)

require (
Expand All @@ -20,18 +20,21 @@ require (
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/briandowns/spinner v1.23.0 // indirect
github.com/charmbracelet/lipgloss v0.10.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/ettle/strcase v0.2.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-github/v30 v30.1.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/lufia/plan9stats v0.0.0-20240408141607-282e7b5d6b74 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
Expand All @@ -46,20 +49,27 @@ require (
github.com/nats-io/nkeys v0.4.7 // indirect
github.com/nats-io/nsc/v2 v2.8.6 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/nix-community/go-nix v0.0.0-20231219074122-93cb24a86856 // indirect
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
github.com/rhysd/go-github-selfupdate v1.2.3 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shirou/gopsutil/v3 v3.24.3 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tcnksm/go-gitconfig v0.1.2 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/tklauser/go-sysconf v0.3.13 // indirect
github.com/tklauser/numcpus v0.7.0 // indirect
github.com/ulikunitz/xz v0.5.12 // indirect
github.com/xlab/tablewriter v0.0.0-20160610135559-80b567a11ad5 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.19.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.33.0 // indirect
Expand Down
Loading

0 comments on commit 5bfcb11

Please sign in to comment.