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 --scalar flag to CLI #280

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add --scalar flag to CLI #280

wants to merge 1 commit into from

Conversation

mahmoud
Copy link
Owner

@mahmoud mahmoud commented Dec 18, 2023

I was using glom in a script this week, specifically to extract single values from API calls. I noticed I kept having to trim the quotes and whitespace off of the JSON output, because even when it's a single value, it's quoted and followed by a newline.

So this feature strips the quotes and whitespace when passed a new flag: --scalar. This is only done when the glom result is not a collection. If it is, it falls back to normal json output.

Some items to consider:

  1. Name?
    • I have SQLAlchemy 2.0 on the brain and scalar is everywhere. But also boltons has an is_scalar function that maps exactly to this, so even if it's jargon-y, I think it's accurate.
  2. Should it be an error if the output is not a single value?
    • I think for my use case the ergonomics would be worse.
  3. Right now, output is always json. Would it be better to do --output "json"|"scalar"?
    • Kinda don't want to get into the business of emitting yaml, etc.?

None of these are blockers, I am good to merge as is.

Copy link

codecov bot commented Dec 18, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (2e0c552) 98.05% compared to head (eed98dd) 98.05%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #280   +/-   ##
=======================================
  Coverage   98.05%   98.05%           
=======================================
  Files          27       27           
  Lines        4362     4371    +9     
  Branches      765      766    +1     
=======================================
+ Hits         4277     4286    +9     
  Misses         54       54           
  Partials       31       31           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

None yet

1 participant