Skip to content

Commit

Permalink
feat: Add short output flag
Browse files Browse the repository at this point in the history
Ref #35
  • Loading branch information
mr-karan committed May 17, 2022
1 parent 7619cbd commit eec8374
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
- [ ] Add tests for CLI Output.
- [ ] Homebrew - Goreleaser
- [ ] Add support for `dig +trace` like functionality.
- [ ] Add `dig +x` short output
- [ ] Add `dig +short` short output
- [x] Add `--strategy` for picking nameservers.
- [ ] Explore `dig.rc` kinda file
- [x] Separate Authority/Answer in JSON output.
Expand Down
1 change: 0 additions & 1 deletion ^

This file was deleted.

1 change: 1 addition & 0 deletions cmd/doggo/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func main() {

// Output Options
f.BoolP("json", "J", false, "Set the output format as JSON")
f.Bool("short", false, "Short output format")
f.Bool("time", false, "Display how long it took for the response to arrive")
f.Bool("color", true, "Show colored output")
f.Bool("debug", false, "Enable debug mode")
Expand Down
1 change: 1 addition & 0 deletions cmd/doggo/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var appHelpTextTemplate = `{{ "NAME" | color "" "heading" }}:
{{ "Output Options" | color "" "heading" }}:
{{"-J, --json " | color "yellow" ""}} Format the output as JSON.
{{"--short" | color "yellow" ""}} Short output format. Shows only the response section.
{{"--color " | color "yellow" ""}} Defaults to true. Set --color=false to disable colored output.
{{"--debug " | color "yellow" ""}} Enable debug logging.
{{"--time" | color "yellow" ""}} Shows how long the response took from the server.
Expand Down
10 changes: 10 additions & 0 deletions internal/app/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ func (app *App) outputJSON(rsp []resolvers.Response) {
fmt.Printf("%s", res)
}

func (app *App) outputShort(rsp []resolvers.Response) {
for _, r := range rsp {
for _, a := range r.Answers {
fmt.Printf("%s\n", a.Address)
}
}
}

func (app *App) outputTerminal(rsp []resolvers.Response) {
var (
green = color.New(color.FgGreen, color.Bold).SprintFunc()
Expand Down Expand Up @@ -134,6 +142,8 @@ func (app *App) outputTerminal(rsp []resolvers.Response) {
func (app *App) Output(responses []resolvers.Response) {
if app.QueryFlags.ShowJSON {
app.outputJSON(responses)
} else if app.QueryFlags.ShortOutput {
app.outputShort(responses)
} else {
app.outputTerminal(responses)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type QueryFlags struct {
Color bool `koanf:"color" json:"-"`
DisplayTimeTaken bool `koanf:"time" json:"-"`
ShowJSON bool `koanf:"json" json:"-"`
ShortOutput bool `koanf:"short" short:"-"`
UseSearchList bool `koanf:"search" json:"-"`
ReverseLookup bool `koanf:"reverse" reverse:"-"`
Strategy string `koanf:"strategy" strategy:"-"`
Expand Down

0 comments on commit eec8374

Please sign in to comment.