From 5ffb8a59b38f622b88504bc8ae707966a0468dba Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sun, 7 Aug 2022 00:40:44 -0400 Subject: [PATCH] make dev after #1067 --- docs/src/manpage.md | 19 ++++++++------ docs/src/manpage.txt | 19 ++++++++------ docs/src/reference-dsl-builtin-functions.md | 10 +++++++- internal/pkg/bifs/system.go | 4 +-- .../pkg/dsl/cst/builtin_function_manager.go | 6 ++--- man/manpage.txt | 19 ++++++++------ man/mlr.1 | 25 +++++++++++++------ 7 files changed, 68 insertions(+), 34 deletions(-) diff --git a/docs/src/manpage.md b/docs/src/manpage.md index b1e7428ee..304a7e116 100644 --- a/docs/src/manpage.md +++ b/docs/src/manpage.md @@ -206,13 +206,13 @@ FUNCTION LIST asserting_not_map asserting_not_null asserting_null asserting_numeric asserting_present asserting_string atan atan2 atanh bitcount boolean capitalize cbrt ceil clean_whitespace collapse_whitespace concat cos cosh - depth dhms2fsec dhms2sec erf erfc every exp expm1 flatten float floor fmtifnum - fmtnum fold format fsec2dhms fsec2hms get_keys get_values gmt2localtime - gmt2sec gssub gsub haskey hexfmt hms2fsec hms2sec hostname int invqnorm - is_absent is_array is_bool is_boolean is_empty is_empty_map is_error is_float - is_int is_map is_nan is_nonempty_map is_not_array is_not_empty is_not_map - is_not_null is_null is_numeric is_present is_string joink joinkv joinv - json_parse json_stringify latin1_to_utf8 leafcount length localtime2gmt + depth dhms2fsec dhms2sec erf erfc every exec exp expm1 flatten float floor + fmtifnum fmtnum fold format fsec2dhms fsec2hms get_keys get_values + gmt2localtime gmt2sec gssub gsub haskey hexfmt hms2fsec hms2sec hostname int + invqnorm is_absent is_array is_bool is_boolean is_empty is_empty_map is_error + is_float is_int is_map is_nan is_nonempty_map is_not_array is_not_empty + is_not_map is_not_null is_null is_numeric is_present is_string joink joinkv + joinv json_parse json_stringify latin1_to_utf8 leafcount length localtime2gmt localtime2sec log log10 log1p logifit lstrip madd mapdiff mapexcept mapselect mapsum max md5 mexp min mmul msub os pow qnorm reduce regextract regextract_or_else round roundm rstrip sec2dhms sec2gmt sec2gmtdate sec2hms @@ -2242,6 +2242,11 @@ FUNCTIONS FOR FILTER/PUT Array example: every(["a", "b", "c"], func(e) {return $[e] >= 0}) Map example: every({"a": "foo", "b": "bar"}, func(k,v) {return $[k] == v}) + exec + (class=system #args=variadic) '$output = exec( "command", ["arg1", "arg2"], {"env": ["ENV_VAR=ENV_VALUE"], "dir": "/tmp/run_command_here", "stdin_string": "this is input fed to program", "combined_output": true )' Run a command via executable, path, args and environment, yielding its stdout minus final carriage return. + Example: + exec("echo", ["Hello", "$YOUR_NAME"], {"env": "YOUR_NAME=World"}) outputs "Hello World" + exp (class=math #args=1) Exponential function e**x. diff --git a/docs/src/manpage.txt b/docs/src/manpage.txt index c26ac0d5f..753c2596d 100644 --- a/docs/src/manpage.txt +++ b/docs/src/manpage.txt @@ -185,13 +185,13 @@ FUNCTION LIST asserting_not_map asserting_not_null asserting_null asserting_numeric asserting_present asserting_string atan atan2 atanh bitcount boolean capitalize cbrt ceil clean_whitespace collapse_whitespace concat cos cosh - depth dhms2fsec dhms2sec erf erfc every exp expm1 flatten float floor fmtifnum - fmtnum fold format fsec2dhms fsec2hms get_keys get_values gmt2localtime - gmt2sec gssub gsub haskey hexfmt hms2fsec hms2sec hostname int invqnorm - is_absent is_array is_bool is_boolean is_empty is_empty_map is_error is_float - is_int is_map is_nan is_nonempty_map is_not_array is_not_empty is_not_map - is_not_null is_null is_numeric is_present is_string joink joinkv joinv - json_parse json_stringify latin1_to_utf8 leafcount length localtime2gmt + depth dhms2fsec dhms2sec erf erfc every exec exp expm1 flatten float floor + fmtifnum fmtnum fold format fsec2dhms fsec2hms get_keys get_values + gmt2localtime gmt2sec gssub gsub haskey hexfmt hms2fsec hms2sec hostname int + invqnorm is_absent is_array is_bool is_boolean is_empty is_empty_map is_error + is_float is_int is_map is_nan is_nonempty_map is_not_array is_not_empty + is_not_map is_not_null is_null is_numeric is_present is_string joink joinkv + joinv json_parse json_stringify latin1_to_utf8 leafcount length localtime2gmt localtime2sec log log10 log1p logifit lstrip madd mapdiff mapexcept mapselect mapsum max md5 mexp min mmul msub os pow qnorm reduce regextract regextract_or_else round roundm rstrip sec2dhms sec2gmt sec2gmtdate sec2hms @@ -2221,6 +2221,11 @@ FUNCTIONS FOR FILTER/PUT Array example: every(["a", "b", "c"], func(e) {return $[e] >= 0}) Map example: every({"a": "foo", "b": "bar"}, func(k,v) {return $[k] == v}) + exec + (class=system #args=variadic) '$output = exec( "command", ["arg1", "arg2"], {"env": ["ENV_VAR=ENV_VALUE"], "dir": "/tmp/run_command_here", "stdin_string": "this is input fed to program", "combined_output": true )' Run a command via executable, path, args and environment, yielding its stdout minus final carriage return. + Example: + exec("echo", ["Hello", "$YOUR_NAME"], {"env": "YOUR_NAME=World"}) outputs "Hello World" + exp (class=math #args=1) Exponential function e**x. diff --git a/docs/src/reference-dsl-builtin-functions.md b/docs/src/reference-dsl-builtin-functions.md index 41318782a..dda502aaa 100644 --- a/docs/src/reference-dsl-builtin-functions.md +++ b/docs/src/reference-dsl-builtin-functions.md @@ -75,7 +75,7 @@ is 2. Unary operators such as `!` and `~` show argument-count of 1; the ternary * [**Higher-order-functions functions**](#higher-order-functions-functions): [any](#any), [apply](#apply), [every](#every), [fold](#fold), [reduce](#reduce), [select](#select), [sort](#sort). * [**Math functions**](#math-functions): [abs](#abs), [acos](#acos), [acosh](#acosh), [asin](#asin), [asinh](#asinh), [atan](#atan), [atan2](#atan2), [atanh](#atanh), [cbrt](#cbrt), [ceil](#ceil), [cos](#cos), [cosh](#cosh), [erf](#erf), [erfc](#erfc), [exp](#exp), [expm1](#expm1), [floor](#floor), [invqnorm](#invqnorm), [log](#log), [log10](#log10), [log1p](#log1p), [logifit](#logifit), [max](#max), [min](#min), [qnorm](#qnorm), [round](#round), [roundm](#roundm), [sgn](#sgn), [sin](#sin), [sinh](#sinh), [sqrt](#sqrt), [tan](#tan), [tanh](#tanh), [urand](#urand), [urand32](#urand32), [urandelement](#urandelement), [urandint](#urandint), [urandrange](#urandrange). * [**String functions**](#string-functions): [capitalize](#capitalize), [clean_whitespace](#clean_whitespace), [collapse_whitespace](#collapse_whitespace), [format](#format), [gssub](#gssub), [gsub](#gsub), [latin1_to_utf8](#latin1_to_utf8), [lstrip](#lstrip), [regextract](#regextract), [regextract_or_else](#regextract_or_else), [rstrip](#rstrip), [ssub](#ssub), [strip](#strip), [strlen](#strlen), [sub](#sub), [substr](#substr), [substr0](#substr0), [substr1](#substr1), [tolower](#tolower), [toupper](#toupper), [truncate](#truncate), [unformat](#unformat), [unformatx](#unformatx), [utf8_to_latin1](#utf8_to_latin1), [\.](#dot). -* [**System functions**](#system-functions): [hostname](#hostname), [os](#os), [system](#system), [version](#version). +* [**System functions**](#system-functions): [exec](#exec), [hostname](#hostname), [os](#os), [system](#system), [version](#version). * [**Time functions**](#time-functions): [dhms2fsec](#dhms2fsec), [dhms2sec](#dhms2sec), [fsec2dhms](#fsec2dhms), [fsec2hms](#fsec2hms), [gmt2localtime](#gmt2localtime), [gmt2sec](#gmt2sec), [hms2fsec](#hms2fsec), [hms2sec](#hms2sec), [localtime2gmt](#localtime2gmt), [localtime2sec](#localtime2sec), [sec2dhms](#sec2dhms), [sec2gmt](#sec2gmt), [sec2gmtdate](#sec2gmtdate), [sec2hms](#sec2hms), [sec2localdate](#sec2localdate), [sec2localtime](#sec2localtime), [strftime](#strftime), [strftime_local](#strftime_local), [strptime](#strptime), [strptime_local](#strptime_local), [systime](#systime), [systimeint](#systimeint), [uptime](#uptime). * [**Typing functions**](#typing-functions): [asserting_absent](#asserting_absent), [asserting_array](#asserting_array), [asserting_bool](#asserting_bool), [asserting_boolean](#asserting_boolean), [asserting_empty](#asserting_empty), [asserting_empty_map](#asserting_empty_map), [asserting_error](#asserting_error), [asserting_float](#asserting_float), [asserting_int](#asserting_int), [asserting_map](#asserting_map), [asserting_nonempty_map](#asserting_nonempty_map), [asserting_not_array](#asserting_not_array), [asserting_not_empty](#asserting_not_empty), [asserting_not_map](#asserting_not_map), [asserting_not_null](#asserting_not_null), [asserting_null](#asserting_null), [asserting_numeric](#asserting_numeric), [asserting_present](#asserting_present), [asserting_string](#asserting_string), [is_absent](#is_absent), [is_array](#is_array), [is_bool](#is_bool), [is_boolean](#is_boolean), [is_empty](#is_empty), [is_empty_map](#is_empty_map), [is_error](#is_error), [is_float](#is_float), [is_int](#is_int), [is_map](#is_map), [is_nan](#is_nan), [is_nonempty_map](#is_nonempty_map), [is_not_array](#is_not_array), [is_not_empty](#is_not_empty), [is_not_map](#is_not_map), [is_not_null](#is_not_null), [is_null](#is_null), [is_numeric](#is_numeric), [is_present](#is_present), [is_string](#is_string), [typeof](#typeof). @@ -1161,6 +1161,14 @@ $* = utf8_to_latin1($*) ## System functions +### exec +
+exec  (class=system #args=variadic) '$output = exec( "command", ["arg1", "arg2"], {"env": ["ENV_VAR=ENV_VALUE"], "dir": "/tmp/run_command_here", "stdin_string": "this is input fed to program", "combined_output": true )' Run a command via executable, path, args and environment, yielding its stdout minus final carriage return.
+Example:
+exec("echo", ["Hello", "$YOUR_NAME"], {"env": "YOUR_NAME=World"}) outputs "Hello World"
+
+ + ### hostname
 hostname  (class=system #args=0) Returns the hostname as a string.
diff --git a/internal/pkg/bifs/system.go b/internal/pkg/bifs/system.go
index af95695da..1a72d15a1 100644
--- a/internal/pkg/bifs/system.go
+++ b/internal/pkg/bifs/system.go
@@ -54,7 +54,7 @@ func BIF_exec(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval {
 	cmd := exec.Command(mlrvals[0].AcquireStringValue())
 	combinedOutput := false
 
-	args := []string { mlrvals[0].AcquireStringValue() }
+	args := []string{mlrvals[0].AcquireStringValue()}
 	if len(mlrvals) > 1 {
 		for _, val := range mlrvals[1].GetArray()[0:] {
 			args = append(args, val.AcquireStringValue())
@@ -66,7 +66,7 @@ func BIF_exec(mlrvals []*mlrval.Mlrval) *mlrval.Mlrval {
 
 		for pe := mlrvals[2].AcquireMapValue().Head; pe != nil; pe = pe.Next {
 			if pe.Key == "env" {
-				env := []string {}
+				env := []string{}
 				for _, val := range pe.Value.GetArray()[0:] {
 					env = append(env, val.AcquireStringValue())
 				}
diff --git a/internal/pkg/dsl/cst/builtin_function_manager.go b/internal/pkg/dsl/cst/builtin_function_manager.go
index f86f7334e..30cf9be91 100644
--- a/internal/pkg/dsl/cst/builtin_function_manager.go
+++ b/internal/pkg/dsl/cst/builtin_function_manager.go
@@ -1929,9 +1929,9 @@ either case it should return a boolean.`,
 		},
 
 		{
-			name:      "exec",
-			class:     FUNC_CLASS_SYSTEM,
-			help:      `'$output = exec(
+			name:  "exec",
+			class: FUNC_CLASS_SYSTEM,
+			help: `'$output = exec(
 	"command",
 	["arg1", "arg2"],
 	{"env": ["ENV_VAR=ENV_VALUE"],
diff --git a/man/manpage.txt b/man/manpage.txt
index c26ac0d5f..753c2596d 100644
--- a/man/manpage.txt
+++ b/man/manpage.txt
@@ -185,13 +185,13 @@ FUNCTION LIST
        asserting_not_map asserting_not_null asserting_null asserting_numeric
        asserting_present asserting_string atan atan2 atanh bitcount boolean
        capitalize cbrt ceil clean_whitespace collapse_whitespace concat cos cosh
-       depth dhms2fsec dhms2sec erf erfc every exp expm1 flatten float floor fmtifnum
-       fmtnum fold format fsec2dhms fsec2hms get_keys get_values gmt2localtime
-       gmt2sec gssub gsub haskey hexfmt hms2fsec hms2sec hostname int invqnorm
-       is_absent is_array is_bool is_boolean is_empty is_empty_map is_error is_float
-       is_int is_map is_nan is_nonempty_map is_not_array is_not_empty is_not_map
-       is_not_null is_null is_numeric is_present is_string joink joinkv joinv
-       json_parse json_stringify latin1_to_utf8 leafcount length localtime2gmt
+       depth dhms2fsec dhms2sec erf erfc every exec exp expm1 flatten float floor
+       fmtifnum fmtnum fold format fsec2dhms fsec2hms get_keys get_values
+       gmt2localtime gmt2sec gssub gsub haskey hexfmt hms2fsec hms2sec hostname int
+       invqnorm is_absent is_array is_bool is_boolean is_empty is_empty_map is_error
+       is_float is_int is_map is_nan is_nonempty_map is_not_array is_not_empty
+       is_not_map is_not_null is_null is_numeric is_present is_string joink joinkv
+       joinv json_parse json_stringify latin1_to_utf8 leafcount length localtime2gmt
        localtime2sec log log10 log1p logifit lstrip madd mapdiff mapexcept mapselect
        mapsum max md5 mexp min mmul msub os pow qnorm reduce regextract
        regextract_or_else round roundm rstrip sec2dhms sec2gmt sec2gmtdate sec2hms
@@ -2221,6 +2221,11 @@ FUNCTIONS FOR FILTER/PUT
        Array example: every(["a", "b", "c"], func(e) {return $[e] >= 0})
        Map example: every({"a": "foo", "b": "bar"}, func(k,v) {return $[k] == v})
 
+   exec
+        (class=system #args=variadic) '$output = exec( "command", ["arg1", "arg2"], {"env": ["ENV_VAR=ENV_VALUE"], "dir": "/tmp/run_command_here", "stdin_string": "this is input fed to program", "combined_output": true )' Run a command via executable, path, args and environment, yielding its stdout minus final carriage return.
+       Example:
+       exec("echo", ["Hello", "$YOUR_NAME"], {"env": "YOUR_NAME=World"}) outputs "Hello World"
+
    exp
         (class=math #args=1) Exponential function e**x.
 
diff --git a/man/mlr.1 b/man/mlr.1
index 9ed3f82ba..48b439b57 100644
--- a/man/mlr.1
+++ b/man/mlr.1
@@ -232,13 +232,13 @@ asserting_map asserting_nonempty_map asserting_not_array asserting_not_empty
 asserting_not_map asserting_not_null asserting_null asserting_numeric
 asserting_present asserting_string atan atan2 atanh bitcount boolean
 capitalize cbrt ceil clean_whitespace collapse_whitespace concat cos cosh
-depth dhms2fsec dhms2sec erf erfc every exp expm1 flatten float floor fmtifnum
-fmtnum fold format fsec2dhms fsec2hms get_keys get_values gmt2localtime
-gmt2sec gssub gsub haskey hexfmt hms2fsec hms2sec hostname int invqnorm
-is_absent is_array is_bool is_boolean is_empty is_empty_map is_error is_float
-is_int is_map is_nan is_nonempty_map is_not_array is_not_empty is_not_map
-is_not_null is_null is_numeric is_present is_string joink joinkv joinv
-json_parse json_stringify latin1_to_utf8 leafcount length localtime2gmt
+depth dhms2fsec dhms2sec erf erfc every exec exp expm1 flatten float floor
+fmtifnum fmtnum fold format fsec2dhms fsec2hms get_keys get_values
+gmt2localtime gmt2sec gssub gsub haskey hexfmt hms2fsec hms2sec hostname int
+invqnorm is_absent is_array is_bool is_boolean is_empty is_empty_map is_error
+is_float is_int is_map is_nan is_nonempty_map is_not_array is_not_empty
+is_not_map is_not_null is_null is_numeric is_present is_string joink joinkv
+joinv json_parse json_stringify latin1_to_utf8 leafcount length localtime2gmt
 localtime2sec log log10 log1p logifit lstrip madd mapdiff mapexcept mapselect
 mapsum max md5 mexp min mmul msub os pow qnorm reduce regextract
 regextract_or_else round roundm rstrip sec2dhms sec2gmt sec2gmtdate sec2hms
@@ -3048,6 +3048,17 @@ Map example: every({"a": "foo", "b": "bar"}, func(k,v) {return $[k] == v})
 .fi
 .if n \{\
 .RE
+.SS "exec"
+.if n \{\
+.RS 0
+.\}
+.nf
+ (class=system #args=variadic) '$output = exec( "command", ["arg1", "arg2"], {"env": ["ENV_VAR=ENV_VALUE"], "dir": "/tmp/run_command_here", "stdin_string": "this is input fed to program", "combined_output": true )' Run a command via executable, path, args and environment, yielding its stdout minus final carriage return.
+Example:
+exec("echo", ["Hello", "$YOUR_NAME"], {"env": "YOUR_NAME=World"}) outputs "Hello World"
+.fi
+.if n \{\
+.RE
 .SS "exp"
 .if n \{\
 .RS 0