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

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