Subject: Config from stdin

From: Emery Hemingway <[email-masked]>
Date: Fri, 26 Sep 2025 08:50:36 +0000

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
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 {