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

reads file from stdin even if argument with file provided #218

Open
dosmanak opened this issue Jan 24, 2024 · 3 comments
Open

reads file from stdin even if argument with file provided #218

dosmanak opened this issue Jan 24, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@dosmanak
Copy link

1️⃣ Description

Using in bash while read line; do yamlfixer $line; done is not working as expected.

📑 Steps to Reproduce

$ echo -e "foo\nbar\nfoobar"| while read line; do yamlfixer -d $line; done
DEBUG: yamlfixer v0.9.15
DEBUG: arguments=Namespace(backup=False, backupsuffix='.orig', debug=True, diffto='/dev/null', ext='yaml,yml,yamllint', forcecolors=False, followsymlinks=False, listfixers=False, nosyntax=False, nochange=False, recurse=0, jsonsummary=False, plainsummary=False, summary=False, tabsize=2, config_file=None, config_data=None, filenames=['foo', '-'])
DEBUG: Fixing <stdin> ... 
DEBUG: Executing linter with 'yamllint --format parsable --strict -'
DEBUG: Linter's exit code is 2
DEBUG: (1+0, 1+0) => [missing document start "---" (document-start)]
DEBUG: Calling fix_missing_docstart("", "bar")
DEBUG: HANDLED: #1
---
bar
foobar
DEBUG: Executing linter with 'yamllint --format parsable --strict -'
DEBUG: Linter's exit code is 0
DEBUG: was fixed

2️⃣ Expected behavior

The debug message shows filenames=['foo', '-']) and the rest of lines are read.
I'd expect, if there is single parameter 'foo', the command will not read from stdin.
Some check of existing file will also help.

Additional context

Thank you for great approach combining yamllint output!

@dosmanak dosmanak added the bug Something isn't working label Jan 24, 2024
@tamere-allo-peter
Copy link
Member

Thanks for your feedback. I don't have any time to work on yamlfixer for now, unfortunately.

@dosmanak
Copy link
Author

Hi, I think there is just some leftover after refactor.
In filenames argument, there is default=["-"] already so I do not see reason for another adding in

if ("-" not in sys.argv[1:]) \

When I removed lines 49-53, it seems working as expected to me:

$ echo -e "foo\nbar\nfoobar"| while read line; do yamlfixer -d $line; done
DEBUG: yamlfixer v0.9.15
DEBUG: arguments=Namespace(backup=False, backupsuffix='.orig', debug=True, diffto='/dev/null', ext='yaml,yml,yamllint', forcecolors=False, followsymlinks=False, listfixers=False, nosyntax=False, nochange=False, recurse=0, jsonsummary=False, plainsummary=False, summary=False, tabsize=2, config_file=None, config_data=None, filenames=['foo'])
DEBUG: yamlfixer v0.9.15
DEBUG: arguments=Namespace(backup=False, backupsuffix='.orig', debug=True, diffto='/dev/null', ext='yaml,yml,yamllint', forcecolors=False, followsymlinks=False, listfixers=False, nosyntax=False, nochange=False, recurse=0, jsonsummary=False, plainsummary=False, summary=False, tabsize=2, config_file=None, config_data=None, filenames=['bar'])
DEBUG: yamlfixer v0.9.15
DEBUG: arguments=Namespace(backup=False, backupsuffix='.orig', debug=True, diffto='/dev/null', ext='yaml,yml,yamllint', forcecolors=False, followsymlinks=False, listfixers=False, nosyntax=False, nochange=False, recurse=0, jsonsummary=False, plainsummary=False, summary=False, tabsize=2, config_file=None, config_data=None, filenames=['foobar'])

vs.

$ echo -e "foo\nbar\nfoobar"| yamlfixer -d
DEBUG: yamlfixer v0.9.15
DEBUG: arguments=Namespace(backup=False, backupsuffix='.orig', debug=True, diffto='/dev/null', ext='yaml,yml,yamllint', forcecolors=False, followsymlinks=False, listfixers=False, nosyntax=False, nochange=False, recurse=0, jsonsummary=False, plainsummary=False, summary=False, tabsize=2, config_file=None, config_data=None, filenames=['-'])
DEBUG: Fixing <stdin> ... 
DEBUG: Executing linter with 'yamllint --format parsable --strict -'
DEBUG: Linter's exit code is 2
DEBUG: (1+0, 1+0) => [missing document start "---" (document-start)]
DEBUG: Calling fix_missing_docstart("", "foo")
DEBUG: HANDLED: #1
---
foo
bar
foobar
DEBUG: Executing linter with 'yamllint --format parsable --strict -'
DEBUG: Linter's exit code is 0
DEBUG: was fixed

dosmanak added a commit to dosmanak/yamlfixer that referenced this issue Jan 30, 2024
@dosmanak
Copy link
Author

So I created PR #219
I am not sure if there is anything special with Github actions, so if you could verify, that would by great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants