public inbox for nncp-devel@lists.stargrave.org
Atom feed
* Config from stdin
@ 2025-09-26  8:50 Emery Hemingway
  2025-09-28  9:12 ` Sergey Matveev
  0 siblings, 1 reply; 2+ messages in thread
From: Emery Hemingway @ 2025-09-26  8:50 UTC (permalink / raw)
  To: nncp-devel

[-- Attachment #1: Type: text/plain, Size: 414 bytes --]

Hi,

A simple feature with a lot of potential value would be to support
passing nncp configuration on FD0 when the path is "-".

With that in place the configuration file can be outside nncp's
view of the file-system.

Also, the configuration could be piped through jq scripts that
attenuate the configuration by removing secret keys that would
be unnecessary for a given operation.


Cheers,
Emery

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: stdin.patch --]
[-- Type: text/x-patch; name=stdin.patch, Size: 1194 bytes --]

diff -Nuar a/src/ctx.go b/src/ctx.go
--- a/src/ctx.go	1981-01-01 00:00:00.000000000 +0000
+++ b/src/ctx.go	2025-09-21 09:44:18.301104773 +0000
@@ -18,6 +18,7 @@
 import (
 	"errors"
 	"fmt"
+	"io"
 	"io/fs"
 	"os"
 	"path/filepath"
@@ -106,25 +107,37 @@
 	if showPrgrs && omitPrgrs {
 		return nil, errors.New("simultaneous -progress and -noprogress")
 	}
-	fi, err := os.Stat(cfgPath)
-	if err != nil {
-		return nil, err
-	}
 	var cfg *CfgJSON
-	if fi.IsDir() {
-		cfg, err = DirToCfg(cfgPath)
+	if cfgPath == "-" {
+		cfgRaw, err := io.ReadAll(os.Stdin)
+		os.Stdin.Close()
 		if err != nil {
 			return nil, err
 		}
-	} else {
-		cfgRaw, err := os.ReadFile(cfgPath)
+		cfg, err = CfgParse(cfgRaw)
 		if err != nil {
 			return nil, err
 		}
-		cfg, err = CfgParse(cfgRaw)
+	} else {
+		fi, err := os.Stat(cfgPath)
 		if err != nil {
 			return nil, err
 		}
+		if fi.IsDir() {
+			cfg, err = DirToCfg(cfgPath)
+			if err != nil {
+				return nil, err
+			}
+		} else {
+			cfgRaw, err := os.ReadFile(cfgPath)
+			if err != nil {
+				return nil, err
+			}
+			cfg, err = CfgParse(cfgRaw)
+			if err != nil {
+				return nil, err
+			}
+		}
 	}
 	ctx, err := Cfg2Ctx(cfg)
 	if err != nil {

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Config from stdin
  2025-09-26  8:50 Config from stdin Emery Hemingway
@ 2025-09-28  9:12 ` Sergey Matveev
  0 siblings, 0 replies; 2+ messages in thread
From: Sergey Matveev @ 2025-09-28  9:12 UTC (permalink / raw)
  To: nncp-devel

[-- Attachment #1: Type: text/plain, Size: 734 bytes --]

Greetings!

*** Emery Hemingway [2025-09-26 08:50]:
>A simple feature with a lot of potential value would be to support
>passing nncp configuration on FD0 when the path is "-".

Looks pretty useful indeed!

I have added it in the 8.13.0 release, but implementation differs.
Instead of passing "-" you pass "FD:x", where "x" is the desired opened
file you fed your configuration to. With "-" and forced stdin you won't
be able to use commands that already read from stdin. With FD:x you may
pass ordinary data to stdin and configuration through separate
independent file. "NNCPCFG=FD:5 nncp-cmd <data 5<cfg"

-- 
Sergey Matveev (http://www.stargrave.org/)
LibrePGP: 12AD 3268 9C66 0D42 6967  FD75 CB82 0563 2107 AD8A

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 265 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-09-28  9:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-26  8:50 Config from stdin Emery Hemingway
2025-09-28  9:12 ` Sergey Matveev