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 input file and os.Stdin support #5

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

Add input file and os.Stdin support #5

wants to merge 1 commit into from

Conversation

pantsing
Copy link

now it can be used as $cat name card.vcf | qrcode -o name card.png


content := strings.Join(flag.Args(), " ")
if *inFile != "" {
Copy link
Owner

Choose a reason for hiding this comment

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

I suggest prioritising the -i flag, then command line arguments, then reading from STDIN last, like:

content := ""
argsContent := strings.Join(flag.Args(), " ")

if *inFile != "" {
	b, err := ioutil.ReadFile(*inFile)
	if err != nil {
		checkError(err)
	}
	content = string(b)
} else if argsContent != "" {
	content = argsContent
} else {
	b, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		checkError(err)
	}
	content = string(b)
}


content := strings.Join(flag.Args(), " ")
if *inFile != "" {
Copy link
Owner

Choose a reason for hiding this comment

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

Hey,

I think reading content from STDIN/a file is a nice addition :)

After this pull request there are three ways to specify content:

  • String from input file:

$ qrcode -i input_filename | display

  • String on command line:

$ qrcode hello | display

  • String on STDIN:

$ echo -n hello | qrcode | display

  • No arguments: (same as string on STDIN, only you type into the terminal and then press Ctrl+D)

$ qrcode | display

If you try the "qrcode hello | display" method, it now hangs and waits for something on STDIN.

I suggest taking content from one source only (first the -i flag, then command line arguments, or lastly STDIN), so the usage is more obvious and easier to explain. This would work well.

thanks,

Tom

@pantsing
Copy link
Author

Thanks Tom, you are right.

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