mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-23 13:52:26 +08:00
Compare commits
5 Commits
c3fad62d8c
...
v2.1.19
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
975c303a31 | ||
|
|
3b8dd94a5c | ||
|
|
815791c0b6 | ||
|
|
a12a691ee6 | ||
|
|
247cf89947 |
@@ -4,7 +4,7 @@
|
|||||||
<br/>
|
<br/>
|
||||||
|
|
||||||

|

|
||||||
[](https://github.com/duke-git/lancet/releases)
|
[](https://github.com/duke-git/lancet/releases)
|
||||||
[](https://pkg.go.dev/github.com/duke-git/lancet/v2)
|
[](https://pkg.go.dev/github.com/duke-git/lancet/v2)
|
||||||
[](https://goreportcard.com/report/github.com/duke-git/lancet/v2)
|
[](https://goreportcard.com/report/github.com/duke-git/lancet/v2)
|
||||||
[](https://github.com/duke-git/lancet/actions/workflows/codecov.yml)
|
[](https://github.com/duke-git/lancet/actions/workflows/codecov.yml)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<br/>
|
<br/>
|
||||||
|
|
||||||

|

|
||||||
[](https://github.com/duke-git/lancet/releases)
|
[](https://github.com/duke-git/lancet/releases)
|
||||||
[](https://pkg.go.dev/github.com/duke-git/lancet/v2)
|
[](https://pkg.go.dev/github.com/duke-git/lancet/v2)
|
||||||
[](https://goreportcard.com/report/github.com/duke-git/lancet/v2)
|
[](https://goreportcard.com/report/github.com/duke-git/lancet/v2)
|
||||||
[](https://github.com/duke-git/lancet/actions/workflows/codecov.yml)
|
[](https://github.com/duke-git/lancet/actions/workflows/codecov.yml)
|
||||||
|
|||||||
@@ -175,11 +175,11 @@ func ExampleReadFileByLine() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ExampleListFileNames() {
|
func ExampleListFileNames() {
|
||||||
fileList, _ := ListFileNames("../formatter/")
|
fileList, _ := ListFileNames("./")
|
||||||
fmt.Println(fileList)
|
fmt.Println(fileList)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// [formatter.go formatter_example_test.go formatter_test.go]
|
// [file.go file_example_test.go file_test.go]
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleZip() {
|
func ExampleZip() {
|
||||||
|
|||||||
@@ -235,10 +235,10 @@ func TestMiMeType(t *testing.T) {
|
|||||||
func TestListFileNames(t *testing.T) {
|
func TestListFileNames(t *testing.T) {
|
||||||
assert := internal.NewAssert(t, "TestListFileNames")
|
assert := internal.NewAssert(t, "TestListFileNames")
|
||||||
|
|
||||||
filesInPath, err := ListFileNames("../formatter/")
|
filesInPath, err := ListFileNames("./")
|
||||||
assert.IsNil(err)
|
assert.IsNil(err)
|
||||||
|
|
||||||
expected := []string{"formatter.go", "formatter_example_test.go", "formatter_test.go"}
|
expected := []string{"file.go", "file_example_test.go", "file_test.go"}
|
||||||
assert.Equal(expected, filesInPath)
|
assert.Equal(expected, filesInPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
system/os.go
12
system/os.go
@@ -15,6 +15,10 @@ import (
|
|||||||
"golang.org/x/text/encoding/simplifiedchinese"
|
"golang.org/x/text/encoding/simplifiedchinese"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
Option func(*exec.Cmd)
|
||||||
|
)
|
||||||
|
|
||||||
// IsWindows check if current os is windows.
|
// IsWindows check if current os is windows.
|
||||||
// Play: https://go.dev/play/p/XzJULbzmf9m
|
// Play: https://go.dev/play/p/XzJULbzmf9m
|
||||||
func IsWindows() bool {
|
func IsWindows() bool {
|
||||||
@@ -66,7 +70,7 @@ func CompareOsEnv(key, comparedEnv string) bool {
|
|||||||
// in linux, use /bin/bash -c to execute command
|
// in linux, use /bin/bash -c to execute command
|
||||||
// in windows, use powershell.exe to execute command
|
// in windows, use powershell.exe to execute command
|
||||||
// Play: https://go.dev/play/p/n-2fLyZef-4
|
// Play: https://go.dev/play/p/n-2fLyZef-4
|
||||||
func ExecCommand(command string) (stdout, stderr string, err error) {
|
func ExecCommand(command string, opts ...Option) (stdout, stderr string, err error) {
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
var errOut bytes.Buffer
|
var errOut bytes.Buffer
|
||||||
|
|
||||||
@@ -74,6 +78,12 @@ func ExecCommand(command string) (stdout, stderr string, err error) {
|
|||||||
if IsWindows() {
|
if IsWindows() {
|
||||||
cmd = exec.Command("powershell.exe", command)
|
cmd = exec.Command("powershell.exe", command)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, opt := range opts {
|
||||||
|
if opt != nil {
|
||||||
|
opt(cmd)
|
||||||
|
}
|
||||||
|
}
|
||||||
cmd.Stdout = &out
|
cmd.Stdout = &out
|
||||||
cmd.Stderr = &errOut
|
cmd.Stderr = &errOut
|
||||||
|
|
||||||
|
|||||||
18
system/os_linux.go
Normal file
18
system/os_linux.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package system
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func WithForeground() Option {
|
||||||
|
return func(c *exec.Cmd) {
|
||||||
|
if c.SysProcAttr == nil {
|
||||||
|
c.SysProcAttr = &syscall.SysProcAttr{
|
||||||
|
Foreground: true,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
c.SysProcAttr.Foreground = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
system/os_windows.go
Normal file
18
system/os_windows.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package system
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func WithWinHide() Option {
|
||||||
|
return func(c *exec.Cmd) {
|
||||||
|
if c.SysProcAttr == nil {
|
||||||
|
c.SysProcAttr = &syscall.SysProcAttr{
|
||||||
|
HideWindow: true,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
c.SysProcAttr.HideWindow = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user