Skip to content

Commit d38a3f4

Browse files
committed
Add split command examples
1 parent edc16ee commit d38a3f4

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
File renamed without changes.

examples_test.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package procs_test
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/ionrock/procs"
7+
)
8+
9+
func ExampleSplitCommand() {
10+
parts := procs.SplitCommand("echo 'hello world'")
11+
for i, p := range parts {
12+
fmt.Printf("%d %s", i+1, p)
13+
}
14+
15+
// Output
16+
// 1 echo
17+
// 2 hello world
18+
}
19+
20+
func ExampleSplitCommandEnv() {
21+
env := map[string]string{
22+
"GREETING": "hello",
23+
"NAME": "world!",
24+
"PASSWORD": "secret",
25+
}
26+
27+
getenv := func(key string) string {
28+
if v, ok := env[key]; ok && key != "PASSWORD" {
29+
return v
30+
}
31+
return ""
32+
}
33+
34+
parts := procs.SplitCommandEnv("echo '$GREETING $NAME $PASSWORD'", getenv)
35+
36+
for i, p := range parts {
37+
fmt.Printf("%d %s", i+1, p)
38+
}
39+
40+
// Output
41+
// 1 echo
42+
// 2 hello world!
43+
}

0 commit comments

Comments
 (0)