Skip to content

Commit

Permalink
as plain text rendering (#31)
Browse files Browse the repository at this point in the history
* as plain text rendering

* updated documentation
  • Loading branch information
aegershman authored Dec 11, 2020
1 parent 93a46b0 commit 7aa9f61
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ updates:
interval: daily
time: "11:00"
open-pull-requests-limit: 10
commit-message:
prefix: "chore(ci)"
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,32 @@ With this plugin, as long as you're logged into the same Cloud Foundry installat

```sh
# get details on a service instance by it's GUID alone
cf rsl -s 4c463943-d421-4f6f-8501-247fba95882d
cf rsl -s 8891ec47-4041-496b-af36-10d89c9513a6

# passing BOSH's default 'service-instance_' prefix is acceptable, too
cf rsl -s service-instance_4c463943-d421-4f6f-8501-247fba95882d
cf rsl -s service-instance_8891ec47-4041-496b-af36-10d89c9513a6

# you can pass '-s service-instance_GUID' multiple times
cf rsl -s service-instance_4c463943-d421-4f6f-8501-247fba95882d -s bbaa77df-52e7-4d6a-8c86-d07a7c93ab82
cf rsl -s service-instance_8891ec47-4041-496b-af36-10d89c9513a6 -s bbaa77df-52e7-4d6a-8c86-d07a7c93ab82

# optionally, multiple different presentation formats can be specified
cf rsl -s xyz --format table (default)
cf rsl -s xyz --format plain-text (default)
cf rsl -s xyz --format table
cf rsl -s xyz --format json

# or both, why not
cf rsl -s xyz --format table --format json
```

`--format plain-text`:

```txt
d6bb8908-a8f8-46b9-9c21-3069cdb939ef
small-redis
grundlework
scratchpad
```

`--format json`:

```json
Expand Down Expand Up @@ -68,13 +78,13 @@ If you want to try it out, install it directly from [the github releases tab as

```sh
# osx 64bit
cf install-plugin -f https://github.com/aegershman/cf-reverse-service-lookup-plugin/releases/download/0.6.0/cf-reverse-service-lookup-plugin-darwin
cf install-plugin -f https://github.com/aegershman/cf-reverse-service-lookup-plugin/releases/download/0.7.0/cf-reverse-service-lookup-plugin-darwin

# linux 64bit (32bit and ARM6 also available)
cf install-plugin -f https://github.com/aegershman/cf-reverse-service-lookup-plugin/releases/download/0.6.0/cf-reverse-service-lookup-plugin-amd64
cf install-plugin -f https://github.com/aegershman/cf-reverse-service-lookup-plugin/releases/download/0.7.0/cf-reverse-service-lookup-plugin-amd64

# windows 64bit (32bit also available)
cf install-plugin -f https://github.com/aegershman/cf-reverse-service-lookup-plugin/releases/download/0.6.0/cf-reverse-service-lookup-plugin-windows-amd64.exe
cf install-plugin -f https://github.com/aegershman/cf-reverse-service-lookup-plugin/releases/download/0.7.0/cf-reverse-service-lookup-plugin-windows-amd64.exe
```

## updating and releasing
Expand All @@ -83,7 +93,7 @@ cf install-plugin -f https://github.com/aegershman/cf-reverse-service-lookup-plu
- `go mod tidy`
- update the plugin version in `main.go`
- update the `README` install-plugin section to reference the new upcoming release version
- `git tag 0.6.0` -- or whatever version, of course
- `git tag 0.7.0` -- or whatever version, of course
- `git push origin --tags`
- `export GITHUB_TOKEN="xyzabc"`
- `goreleaser release`
Expand Down
7 changes: 4 additions & 3 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ tasks:
test:
cmds:
- task: install
- cf rsl -s db8dba61-32c7-4834-b94b-b3d61240d47b --format json | jq '.'
- cf rsl -s db8dba61-32c7-4834-b94b-b3d61240d47b --format table --format json
- cf rsl -s db8dba61-32c7-4834-b94b-b3d61240d47b -s db8dba61-32c7-4834-b94b-b3d61240d47b
- cf rsl -s 8891ec47-4041-496b-af36-10d89c9513a6
- cf rsl -s 8891ec47-4041-496b-af36-10d89c9513a6 --format json | jq '.'
- cf rsl -s 8891ec47-4041-496b-af36-10d89c9513a6 --format table --format plain-text --format json
- cf rsl -s 8891ec47-4041-496b-af36-10d89c9513a6 -s 8891ec47-4041-496b-af36-10d89c9513a6
- task: uninstall
4 changes: 2 additions & 2 deletions cmd/rsl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (cmd *reverseServiceLookupCmd) GetMetadata() plugin.PluginMetadata {
Name: "cf-reverse-service-lookup-plugin",
Version: plugin.VersionType{
Major: 0,
Minor: 6,
Minor: 7,
Build: 0,
},
Commands: []plugin.Command{
Expand All @@ -97,7 +97,7 @@ func (cmd *reverseServiceLookupCmd) GetMetadata() plugin.PluginMetadata {
UsageDetails: plugin.Usage{
Usage: "cf rsl [-s service_instance-xyzabc...]",
Options: map[string]string{
"format": "format to present (options: table,json) (default: table)",
"format": "format to present (options: table,json,plain-text) (default: plain-text)",
"s": "service_instance-GUID to look up. Can be of form 'service_instance-xyzguid123' or just 'xyzguid123'",
"trim-prefix": "if your services are prefixed with something besides BOSH defaults, change this to be the string prefix before the service GUID... also, if you have that use-case, definitely let me know, I'm intrigued. (default: service_instance-)",
},
Expand Down
18 changes: 17 additions & 1 deletion internal/v2client/presenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package v2client

import (
"encoding/json"
"fmt"
"io"
"log"
"strings"

"github.com/olekukonko/tablewriter"
)
Expand All @@ -27,7 +29,7 @@ func NewPresenter(formats []string, serviceReports []ServiceReport, writer io.Wr
// Render -
func (p *Presenter) Render() {
if len(p.formats) == 0 {
p.asTable()
p.asPlainText()
}

for _, f := range p.formats {
Expand All @@ -36,10 +38,24 @@ func (p *Presenter) Render() {
p.asTable()
case "json":
p.asJSON()
case "plain-text":
p.asPlainText()
}
}
}

func (p *Presenter) asPlainText() {
for _, report := range p.serviceReports {
fieldsJoined := strings.Join([]string{
report.Service.GUID,
report.Service.Name,
report.Organization.Name,
report.Space.Name,
}, "\n")
fmt.Println(fieldsJoined)
}
}

func (p *Presenter) asTable() {
table := tablewriter.NewWriter(p.writer)
table.SetHeader([]string{
Expand Down

0 comments on commit 7aa9f61

Please sign in to comment.