docs(users/Profpatsch/lib): move split-stdin to lib & document
Change-Id: I39e81ed766cb209ded5309ea962a59a6f1c811c9 Reviewed-on: https://cl.tvl.fyi/c/depot/+/3285 Tested-by: BuildkiteCI Reviewed-by: Profpatsch <mail@profpatsch.de>
This commit is contained in:
		
							parent
							
								
									4e2879282d
								
							
						
					
					
						commit
						2835e5ec7e
					
				
					 2 changed files with 24 additions and 7 deletions
				
			
		|  | @ -162,11 +162,6 @@ let | |||
|     '' | ||||
|   ]; | ||||
| 
 | ||||
|   split-stdin = depot.nix.writeExecline "split-stdin" { argMode = "env"; } [ | ||||
|     "pipeline" [ "runblock" "1" bins.bash "-c" ''${bins.tee} >("$@")'' "bash-split-stdin" ] | ||||
|     "runblock" "-r" "1" | ||||
|   ]; | ||||
| 
 | ||||
|   capture-stdin = depot.nix.writers.rustSimple { | ||||
|     name = "capture-stdin"; | ||||
|     dependencies = [ depot.users.Profpatsch.execline.exec-helpers ]; | ||||
|  | @ -231,7 +226,6 @@ in depot.nix.utils.drvTargets { | |||
|    inherit | ||||
|     router | ||||
|     notes-server | ||||
|     split-stdin | ||||
|     index | ||||
|     router-lookup | ||||
|     ; | ||||
|  |  | |||
|  | @ -1,9 +1,11 @@ | |||
| { depot, pkgs, ... }: | ||||
| let | ||||
|   bins = depot.nix.getBins pkgs.coreutils [ "printf" "echo" "cat" "printenv" ] | ||||
|   bins = depot.nix.getBins pkgs.coreutils [ "printf" "echo" "cat" "printenv" "tee" ] | ||||
|       // depot.nix.getBins pkgs.bash [ "bash" ] | ||||
|       // depot.nix.getBins pkgs.fdtools [ "multitee" ] | ||||
|       ; | ||||
| 
 | ||||
|   # Print `msg` and and argv to stderr, then execute into argv | ||||
|   debugExec = msg: depot.nix.writeExecline "debug-exec" {} [ | ||||
|     "if" [ | ||||
|       "fdmove" "-c" "1" "2" | ||||
|  | @ -13,10 +15,12 @@ let | |||
|     "$@" | ||||
|   ]; | ||||
| 
 | ||||
|   # Print stdin to stderr and stdout | ||||
|   eprint-stdin = depot.nix.writeExecline "eprint-stdin" {} [ | ||||
|     "pipeline" [ bins.multitee "0-1,2" ] "$@" | ||||
|   ]; | ||||
| 
 | ||||
|   # Assume the input on stdin is netencode, pretty print it to stderr and forward it to stdout | ||||
|   eprint-stdin-netencode = depot.nix.writeExecline "eprint-stdin-netencode" {} [ | ||||
|     "pipeline" [ | ||||
|       # move stdout to 3 | ||||
|  | @ -30,6 +34,7 @@ let | |||
|     "$@" | ||||
|   ]; | ||||
| 
 | ||||
|   # print the given environment variable in $1 to stderr, then execute into the rest of argv | ||||
|   eprintenv = depot.nix.writeExecline "eprintenv" { readNArgs = 1; } [ | ||||
|     "ifelse" [ "fdmove" "-c" "1" "2" bins.printenv "$1" ] | ||||
|     [ "$@" ] | ||||
|  | @ -37,6 +42,23 @@ let | |||
|     "$@" | ||||
|   ]; | ||||
| 
 | ||||
|   # Split stdin into two commands, given by a block and the rest of argv | ||||
|   # | ||||
|   # Example (execline): | ||||
|   # | ||||
|   #   pipeline [ echo foo ] | ||||
|   #   split-stdin [ fdmove 1 2 foreground [ cat ] echo "bar" ] cat | ||||
|   # | ||||
|   #   stdout: foo\n | ||||
|   #   stderr: foo\nbar\n | ||||
|   split-stdin = depot.nix.writeExecline "split-stdin" { argMode = "env"; } [ | ||||
|     "pipeline" [ | ||||
|       # this is horrible yes but the quickest way I knew how to implement it | ||||
|       "runblock" "1" bins.bash "-c" ''${bins.tee} >("$@")'' "bash-split-stdin" | ||||
|     ] | ||||
|     "runblock" "-r" "1" | ||||
|   ]; | ||||
| 
 | ||||
|   # remove everything but a few selected environment variables | ||||
|   runInEmptyEnv = keepVars: | ||||
|     let | ||||
|  | @ -53,6 +75,7 @@ in { | |||
|     eprint-stdin | ||||
|     eprint-stdin-netencode | ||||
|     eprintenv | ||||
|     split-stdin | ||||
|     runInEmptyEnv | ||||
|     ; | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue