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 Option and Refactor Data Preparation #142

Merged
merged 2 commits into from
Nov 7, 2024

Conversation

egze
Copy link
Contributor

@egze egze commented Nov 6, 2024

This pull request introduces a new -json flag, allowing output in JSON format for more flexible data handling and integration with other scripts. At the moment I'm trying to make enpass-cli work with Kamal basecamp/kamal#1189 (comment)

The change refactors the code by encapsulating card data preparation and output functionalities into reusable functions: prepareCardData and outputDataOrLog. The key points of this PR are:

Simple usage

> go run ./cmd/... -json -vault=path/to/vault list FooBar

Enter vault password:
[{"category":"computer","label":"DB_PASSWORD","login":"","title":"FooBar","type":"password"},{"category":"computer","label":"OTHER_SECRET","login":"","title":"FooBar","type":"password"},{"category":"computer","label":"","login":"","title":"FooBar","type":"password"},{"category":"computer","label":"","login":"","title":"FooBar","type":"password"}]

In combination with other scripts

> go run ./cmd/... -json -vault=path/to/vault list FooBar | jq

Enter vault password:
[
  {
    "category": "computer",
    "label": "DB_PASSWORD",
    "login": "",
    "title": "FooBar",
    "type": "password"
  },
  {
    "category": "computer",
    "label": "OTHER_SECRET",
    "login": "",
    "title": "FooBar",
    "type": "password"
  },
  {
    "category": "computer",
    "label": "",
    "login": "",
    "title": "FooBar",
    "type": "password"
  },
  {
    "category": "computer",
    "label": "",
    "login": "",
    "title": "FooBar",
    "type": "password"
  }
]

The same also works with show function.

@hazcod hazcod merged commit a0a871d into hazcod:master Nov 7, 2024
5 checks passed
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