@@ -15,13 +15,15 @@ import (
1515
1616var publish = & cli.Command {
1717 Name : "publish" ,
18- Usage : "publishes a note with content from stdin" ,
19- Description : `reads content from stdin and publishes it as a note, optionally as a reply to another note.
18+ Usage : "publishes a note with content from stdin or argument" ,
19+ Description : `reads content and publishes it as a note, optionally as a reply to another note.
20+ Either pipe content or pass it as the first argument.
2021
2122example:
2223 echo "hello world" | nak publish
24+ nak publish "hello world"
2325 echo "I agree!" | nak publish --reply nevent1...
24- echo "tagged post" | nak publish -t t=mytag -t e=someeventid` ,
26+ nak publish -t t=mytag -t e=someeventid "tagged post" ` ,
2527 DisableSliceFlagSeparator : true ,
2628 Flags : combineFlags ([][]cli.Flag {},
2729 & cli.StringFlag {
@@ -52,9 +54,17 @@ example:
5254 },
5355 ),
5456 Action : func (ctx context.Context , c * cli.Command ) error {
55- content , err := io .ReadAll (os .Stdin )
56- if err != nil {
57- return fmt .Errorf ("failed to read from stdin: %w" , err )
57+ var content []byte
58+ if isPiped () {
59+ var err error
60+ content , err = io .ReadAll (os .Stdin )
61+ if err != nil {
62+ return fmt .Errorf ("failed to read from stdin: %w" , err )
63+ }
64+ } else if firstArg := c .Args ().First (); firstArg != "" {
65+ content = []byte (firstArg )
66+ } else {
67+ return fmt .Errorf ("no content. pipe or pass content as argument." )
5868 }
5969
6070 evt := nostr.Event {
0 commit comments