Skip to content

Commit 994e8f1

Browse files
committed
fix: examplegen
1 parent 913afc9 commit 994e8f1

3 files changed

Lines changed: 67 additions & 71 deletions

File tree

README.md

Lines changed: 63 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<img src="https://img.shields.io/github/v/tag/goforj/execx?label=version&sort=semver" alt="Latest tag">
1515
<a href="https://codecov.io/gh/goforj/execx" ><img src="https://codecov.io/github/goforj/execx/graph/badge.svg?token=RBB8T6WQ0U"/></a>
1616
<!-- test-count:embed:start -->
17-
<img src="https://img.shields.io/badge/tests-100-brightgreen" alt="Tests">
17+
<img src="https://img.shields.io/badge/tests-114-brightgreen" alt="Tests">
1818
<!-- test-count:embed:end -->
1919
<a href="https://goreportcard.com/report/github.com/goforj/execx"><img src="https://goreportcard.com/badge/github.com/goforj/execx" alt="Go Report Card"></a>
2020
</p>
@@ -203,8 +203,8 @@ All public APIs are covered by runnable examples under `./examples`, and the tes
203203
| **Process** | [GracefulShutdown](#gracefulshutdown) [Interrupt](#interrupt) [KillAfter](#killafter) [Send](#send) [Terminate](#terminate) [Wait](#wait) |
204204
| **Results** | [IsExitCode](#isexitcode) [IsSignal](#issignal) [OK](#ok) |
205205
| **Streaming** | [OnStderr](#onstderr) [OnStdout](#onstdout) [StderrWriter](#stderrwriter) [StdoutWriter](#stdoutwriter) |
206+
| **User Feedback** | [ShadowPrint](#shadowprint) [ShadowPrintFormatter](#shadowprintformatter) [ShadowPrintMask](#shadowprintmask) [ShadowPrintOff](#shadowprintoff) [ShadowPrintPrefix](#shadowprintprefix) |
206207
| **WorkingDir** | [Dir](#dir) |
207-
| **User Feedback** | [ShadowPrint](#shadowprint) [ShadowPrintOff](#shadowprintoff) [ShadowPrintPrefix](#shadowprintprefix) [ShadowPrintMask](#shadowprintmask) [ShadowPrintFormatter](#shadowprintformatter) |
208208

209209

210210
## Arguments
@@ -289,62 +289,6 @@ fmt.Println(cmd.ShellEscaped())
289289
// #string echo 'hello world' 'it'\\''s'
290290
```
291291

292-
## User Feedback
293-
294-
### <a id="shadowprint"></a>ShadowPrint
295-
296-
ShadowPrint writes the shell-escaped command to stderr before and after execution.
297-
298-
```go
299-
_, _ = execx.Command("printf", "hi").ShadowPrint().Run()
300-
// execx > printf hi
301-
// execx > printf hi (1ms)
302-
```
303-
304-
### <a id="shadowprintoff"></a>ShadowPrintOff
305-
306-
ShadowPrintOff disables shadow printing for this command chain.
307-
308-
```go
309-
_, _ = execx.Command("printf", "hi").ShadowPrint().ShadowPrintOff().Run()
310-
```
311-
312-
### <a id="shadowprintprefix"></a>ShadowPrintPrefix
313-
314-
ShadowPrintPrefix sets the prefix used by ShadowPrint.
315-
316-
```go
317-
_, _ = execx.Command("printf", "hi").ShadowPrintPrefix("run").Run()
318-
// run > printf hi
319-
// run > printf hi (1ms)
320-
```
321-
322-
### <a id="shadowprintmask"></a>ShadowPrintMask
323-
324-
ShadowPrintMask applies a masker to the shadow-printed command string.
325-
326-
```go
327-
mask := func(cmd string) string {
328-
return strings.ReplaceAll(cmd, "secret", "***")
329-
}
330-
_, _ = execx.Command("printf", "secret").ShadowPrintMask(mask).Run()
331-
// execx > printf ***
332-
// execx > printf *** (1ms)
333-
```
334-
335-
### <a id="shadowprintformatter"></a>ShadowPrintFormatter
336-
337-
ShadowPrintFormatter sets a formatter for ShadowPrint output.
338-
339-
```go
340-
formatter := func(ev execx.ShadowEvent) string {
341-
return fmt.Sprintf("shadow: %s %s", ev.Phase, ev.Command)
342-
}
343-
_, _ = execx.Command("printf", "hi").ShadowPrintFormatter(formatter).Run()
344-
// shadow: before printf hi
345-
// shadow: after printf hi
346-
```
347-
348292
### <a id="string"></a>String
349293

350294
String returns a human-readable representation of the command.
@@ -551,17 +495,9 @@ fmt.Println(out)
551495

552496
## OS Controls
553497

554-
OS controls map to `syscall.SysProcAttr` for process/session configuration. Use them when you need process groups, detached sessions, or OS-specific process creation flags. On unsupported platforms they are no-ops.
555-
556498
### <a id="creationflags"></a>CreationFlags
557499

558-
CreationFlags sets Windows process creation flags (for example, create a new process group). It is a no-op on non-Windows platforms.
559-
560-
Common flags:
561-
562-
- `execx.CreateNewProcessGroup`
563-
- `execx.CreateNewConsole`
564-
- `execx.CreateNoWindow`
500+
CreationFlags is a no-op on non-Windows platforms; on Windows it sets process creation flags.
565501

566502
```go
567503
out, _ := execx.Command("printf", "ok").CreationFlags(execx.CreateNewProcessGroup).Output()
@@ -571,7 +507,7 @@ fmt.Print(out)
571507

572508
### <a id="hidewindow"></a>HideWindow
573509

574-
HideWindow hides console windows on Windows (it sets `SysProcAttr.HideWindow` and `CREATE_NO_WINDOW`). It is a no-op on non-Windows platforms.
510+
HideWindow is a no-op on non-Windows platforms; on Windows it hides console windows.
575511

576512
```go
577513
out, _ := execx.Command("printf", "ok").HideWindow(true).Output()
@@ -581,7 +517,7 @@ fmt.Print(out)
581517

582518
### <a id="pdeathsig"></a>Pdeathsig
583519

584-
Pdeathsig sets a parent-death signal on Linux so the child receives a signal if the parent exits. It is a no-op on non-Linux platforms.
520+
Pdeathsig sets a parent-death signal on Linux so the child is signaled if the parent exits.
585521

586522
```go
587523
out, _ := execx.Command("printf", "ok").Pdeathsig(syscall.SIGTERM).Output()
@@ -591,7 +527,7 @@ fmt.Print(out)
591527

592528
### <a id="setpgid"></a>Setpgid
593529

594-
Setpgid places the child in a new process group. Use this when you want to signal or terminate a group independently of the parent.
530+
Setpgid places the child in a new process group for group signals.
595531

596532
```go
597533
out, _ := execx.Command("printf", "ok").Setpgid(true).Output()
@@ -601,7 +537,7 @@ fmt.Print(out)
601537

602538
### <a id="setsid"></a>Setsid
603539

604-
Setsid starts the child in a new session, detaching it from the controlling terminal.
540+
Setsid starts the child in a new session, detaching it from the terminal.
605541

606542
```go
607543
out, _ := execx.Command("printf", "ok").Setsid(true).Output()
@@ -830,6 +766,62 @@ fmt.Print(out.String())
830766
// hello
831767
```
832768

769+
## User Feedback
770+
771+
### <a id="shadowprint"></a>ShadowPrint
772+
773+
ShadowPrint writes the shell-escaped command to stderr before and after execution.
774+
775+
```go
776+
_, _ = execx.Command("printf", "hi").ShadowPrint().Run()
777+
// execx > printf hi
778+
// execx > printf hi (1ms)
779+
```
780+
781+
### <a id="shadowprintformatter"></a>ShadowPrintFormatter
782+
783+
ShadowPrintFormatter sets a formatter for ShadowPrint output.
784+
785+
```go
786+
formatter := func(ev execx.ShadowEvent) string {
787+
return fmt.Sprintf("shadow: %s %s", ev.Phase, ev.Command)
788+
}
789+
_, _ = execx.Command("printf", "hi").ShadowPrintFormatter(formatter).Run()
790+
// shadow: before printf hi
791+
// shadow: after printf hi
792+
```
793+
794+
### <a id="shadowprintmask"></a>ShadowPrintMask
795+
796+
ShadowPrintMask sets a command masker for ShadowPrint output.
797+
798+
```go
799+
mask := func(cmd string) string {
800+
return strings.ReplaceAll(cmd, "secret", "***")
801+
}
802+
_, _ = execx.Command("printf", "secret").ShadowPrintMask(mask).Run()
803+
// execx > printf ***
804+
// execx > printf *** (1ms)
805+
```
806+
807+
### <a id="shadowprintoff"></a>ShadowPrintOff
808+
809+
ShadowPrintOff disables shadow printing for this command chain.
810+
811+
```go
812+
_, _ = execx.Command("printf", "hi").ShadowPrint().ShadowPrintOff().Run()
813+
```
814+
815+
### <a id="shadowprintprefix"></a>ShadowPrintPrefix
816+
817+
ShadowPrintPrefix sets the prefix used by ShadowPrint.
818+
819+
```go
820+
_, _ = execx.Command("printf", "hi").ShadowPrintPrefix("run").Run()
821+
// run > printf hi
822+
// run > printf hi (1ms)
823+
```
824+
833825
## WorkingDir
834826

835827
### <a id="dir"></a>Dir

docs/examplegen/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ func writeMain(base string, fd *FuncDoc, importPath string) error {
394394
if strings.Contains(ex.Code, "regexp.") {
395395
imports["regexp"] = true
396396
}
397+
if strings.Contains(ex.Code, "syscall.") {
398+
imports["syscall"] = true
399+
}
397400
if strings.Contains(ex.Code, "redis.") {
398401
imports["github.com/redis/go-redis/v9"] = true
399402
}

examples/pdeathsig/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package main
66
import (
77
"fmt"
88
"github.com/goforj/execx"
9+
"syscall"
910
)
1011

1112
func main() {

0 commit comments

Comments
 (0)