Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSON output for blocks command #26

Merged
merged 10 commits into from
Sep 13, 2020
Merged

Conversation

gdavison
Copy link
Contributor

@gdavison gdavison commented Aug 6, 2020

Add the option for JSON blocks output to feed into other tools using, e.g. jq. Uses the flags --json or -j.

Output format is

{
    "block_count": 1,
    "blocks": [
        {
            "start_line": 4,
            "end_line": 9,
            "text": "..."
        }
    ]
}

Depends on #25 and #22

return encoder.Encode(w.data)
}

func findBlocksInFile(fs afero.Fs, log *logrus.Logger, filename string, verbose, zeroTerminated, jsonOutput bool, stdin io.Reader, stdout, stderr io.Writer) error {
Copy link
Contributor Author

@gdavison gdavison Aug 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is starting to feel a bit unwieldy, with all the flags being passed as parameters. At some point, a command object containing the configuration should probably be created.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, but that is for another pr!

Copy link
Owner

@katbyte katbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

return encoder.Encode(w.data)
}

func findBlocksInFile(fs afero.Fs, log *logrus.Logger, filename string, verbose, zeroTerminated, jsonOutput bool, stdin io.Reader, stdout, stderr io.Writer) error {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, but that is for another pr!

@katbyte katbyte added this to the v0.3.0 milestone Aug 13, 2020
@katbyte katbyte merged commit 3b33300 into katbyte:master Sep 13, 2020
@gdavison gdavison deleted the json-output branch October 9, 2020 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants