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

feat: add support for output modifier flags #14

Merged
merged 10 commits into from Dec 12, 2022

Conversation

ruicalheno133
Copy link
Contributor

Currently, only -e option is used to execute an inline script.

This PR:

  • Adds support for osascript's output modifier flags -s (as specified here).
  • Adds tests to ensure current behaviour is kept and -s flag behaviour works

I'm not sure if this solves #4, but using the -s s flag, it returns a string that can be parsed into an array. Neverthless, I think it is useful to have this option available to mirror the behaviour of the osascript command,.

Output without -s flag:

$ osascript -e 'return {{"foo", {"bar"}}}'        
foo, bar

Output with -s flag:

$ osascript -e 'return {{"foo", {"bar"}}}'  -s s
{{"foo", {"bar"}}}

@sindresorhus
Copy link
Owner

The point of this package is to abstract away the command-line flags. I think this should instead be an option called humanReadableReturnValue that can be set to false to get the wanted behavior.

@ruicalheno133
Copy link
Contributor Author

Got it 👍 Will update accordingly.

As a follow-up, I was wondering if it wouldn't be useful to also be able to read from a file. I could create a new function specifically for that or add a new argument fromFile and if this was set to true it would consider the script param as a filename. What do you think?

@sindresorhus
Copy link
Owner

As a follow-up, I was wondering if it wouldn't be useful to also be able to read from a file. I could create a new function specifically for that or add a new argument fromFile and if this was set to true it would consider the script param as a filename. What do you think?

I think the most common use-case for this package are short scripts you can just have inline. If you need to pass a file, you can simply call fs.readFile.

@ruicalheno133
Copy link
Contributor Author

Right! Let's keep it simple.

I added a new argument humanReadableOutput to the existing functions in 282e882.
I thought wrapping it within an options object, but it seemed overkill since there are no more options to be defined.

@sindresorhus
Copy link
Owner

I thought wrapping it within an options object, but it seemed overkill since there are no more options to be defined.

I think it should be an options-object.

runApplescript(..., false) is not very readable.

@sindresorhus
Copy link
Owner

https://github.com/sindresorhus/typescript-definition-style-guide#documentation

index.d.ts Outdated Show resolved Hide resolved
index.d.ts Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
index.d.ts Show resolved Hide resolved
@sindresorhus
Copy link
Owner

Don't forget to add it to the readme. Use this formatting: https://github.com/sindresorhus/boxen#options

@sindresorhus
Copy link
Owner

Don't forget to add it to the readme. Use this formatting: https://github.com/sindresorhus/boxen#options

readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
@ruicalheno133 ruicalheno133 force-pushed the feature/osascript-flags branch 2 times, most recently from 650f18d to a59bcaa Compare December 7, 2022 14:35
@sindresorhus sindresorhus merged commit 8215646 into sindresorhus:main Dec 12, 2022
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

2 participants