build(deps): bump github.com/gookit/config/v2 from 2.2.6 to 2.2.7
Bumps [github.com/gookit/config/v2](https://github.com/gookit/config) from 2.2.6 to 2.2.7. - [Release notes](https://github.com/gookit/config/releases) - [Commits](https://github.com/gookit/config/compare/v2.2.6...v2.2.7) --- updated-dependencies: - dependency-name: github.com/gookit/config/v2 dependency-version: 2.2.7 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
+2
@@ -88,6 +88,8 @@ err = rr.Run()
|
||||
|
||||
### Functions API
|
||||
|
||||
> generate by: `go doc ./sysutil`
|
||||
|
||||
```go
|
||||
func BinDir() string
|
||||
func BinFile() string
|
||||
|
||||
+30
-22
@@ -19,10 +19,12 @@ type Cmd struct {
|
||||
*exec.Cmd
|
||||
// Name of the command
|
||||
Name string
|
||||
// DryRun if True, not real execute command
|
||||
// DryRun setting. if True, not really execute command
|
||||
DryRun bool
|
||||
// Vars mapping
|
||||
// Vars mapping TODO
|
||||
Vars map[string]string
|
||||
// PrintLine placeholder for print command cline.
|
||||
PrintLine string
|
||||
|
||||
// BeforeRun hook
|
||||
BeforeRun func(c *Cmd)
|
||||
@@ -87,6 +89,12 @@ func (c *Cmd) PrintCmdline() *Cmd {
|
||||
return c
|
||||
}
|
||||
|
||||
// PrintCmdline2 on exec command
|
||||
func (c *Cmd) PrintCmdline2() *Cmd {
|
||||
c.BeforeRun = PrintCmdline2
|
||||
return c
|
||||
}
|
||||
|
||||
// OnBefore exec add hook
|
||||
func (c *Cmd) OnBefore(fn func(c *Cmd)) *Cmd {
|
||||
c.BeforeRun = fn
|
||||
@@ -135,7 +143,7 @@ func (c *Cmd) WithWorkDir(dir string) *Cmd {
|
||||
|
||||
// WorkDirOnNE set workdir on input is not empty
|
||||
func (c *Cmd) WorkDirOnNE(dir string) *Cmd {
|
||||
if dir == "" {
|
||||
if dir != "" {
|
||||
c.Dir = dir
|
||||
}
|
||||
return c
|
||||
@@ -169,9 +177,7 @@ func (c *Cmd) AppendEnv(mp map[string]string) *Cmd {
|
||||
}
|
||||
|
||||
// OutputToOS output to OS stdout and error
|
||||
func (c *Cmd) OutputToOS() *Cmd {
|
||||
return c.ToOSStdoutStderr()
|
||||
}
|
||||
func (c *Cmd) OutputToOS() *Cmd { return c.ToOSStdoutStderr() }
|
||||
|
||||
// ToOSStdoutStderr output to OS stdout and error
|
||||
func (c *Cmd) ToOSStdoutStderr() *Cmd {
|
||||
@@ -208,27 +214,25 @@ func (c *Cmd) WithAnyArgs(args ...any) *Cmd {
|
||||
return c
|
||||
}
|
||||
|
||||
// AddArg add args and returns the current object
|
||||
// AddArg add args and return the current object
|
||||
func (c *Cmd) AddArg(args ...string) *Cmd { return c.WithArg(args...) }
|
||||
|
||||
// WithArg add args and returns the current object. alias of the WithArg()
|
||||
// WithArg add args and return the current object. alias of the WithArg()
|
||||
func (c *Cmd) WithArg(args ...string) *Cmd {
|
||||
c.Args = append(c.Args, args...)
|
||||
return c
|
||||
}
|
||||
|
||||
// AddArgf add args and returns the current object. alias of the WithArgf()
|
||||
func (c *Cmd) AddArgf(format string, args ...any) *Cmd {
|
||||
return c.WithArgf(format, args...)
|
||||
}
|
||||
// AddArgf add args and return the current object. alias of the WithArgf()
|
||||
func (c *Cmd) AddArgf(format string, args ...any) *Cmd { return c.WithArgf(format, args...) }
|
||||
|
||||
// WithArgf add arg and returns the current object
|
||||
// WithArgf add arg and return the current object
|
||||
func (c *Cmd) WithArgf(format string, args ...any) *Cmd {
|
||||
c.Args = append(c.Args, fmt.Sprintf(format, args...))
|
||||
return c
|
||||
}
|
||||
|
||||
// ArgIf add arg and returns the current object
|
||||
// ArgIf add arg and return the current object
|
||||
func (c *Cmd) ArgIf(arg string, exprOk bool) *Cmd {
|
||||
if exprOk {
|
||||
c.Args = append(c.Args, arg)
|
||||
@@ -236,7 +240,7 @@ func (c *Cmd) ArgIf(arg string, exprOk bool) *Cmd {
|
||||
return c
|
||||
}
|
||||
|
||||
// WithArgIf add arg and returns the current object
|
||||
// WithArgIf add arg and return the current object
|
||||
func (c *Cmd) WithArgIf(arg string, exprOk bool) *Cmd {
|
||||
return c.ArgIf(arg, exprOk)
|
||||
}
|
||||
@@ -252,7 +256,7 @@ func (c *Cmd) WithArgs(args []string) *Cmd {
|
||||
return c
|
||||
}
|
||||
|
||||
// WithArgsIf add arg and returns the current object
|
||||
// WithArgsIf add arg and return the current object
|
||||
func (c *Cmd) WithArgsIf(args []string, exprOk bool) *Cmd {
|
||||
if exprOk && len(args) > 0 {
|
||||
c.Args = append(c.Args, args...)
|
||||
@@ -260,7 +264,7 @@ func (c *Cmd) WithArgsIf(args []string, exprOk bool) *Cmd {
|
||||
return c
|
||||
}
|
||||
|
||||
// WithVars add vars and returns the current object
|
||||
// WithVars add vars and return the current object
|
||||
func (c *Cmd) WithVars(vs map[string]string) *Cmd {
|
||||
if len(vs) > 0 {
|
||||
c.Vars = vs
|
||||
@@ -268,7 +272,7 @@ func (c *Cmd) WithVars(vs map[string]string) *Cmd {
|
||||
return c
|
||||
}
|
||||
|
||||
// SetVar add var and returns the current object
|
||||
// SetVar add var and return the current object
|
||||
func (c *Cmd) SetVar(name, val string) *Cmd {
|
||||
c.Vars[name] = val
|
||||
return c
|
||||
@@ -320,12 +324,16 @@ func (c *Cmd) ResetArgs() {
|
||||
}
|
||||
|
||||
// Workdir of the command
|
||||
func (c *Cmd) Workdir() string {
|
||||
return c.Dir
|
||||
}
|
||||
func (c *Cmd) Workdir() string { return c.Dir }
|
||||
|
||||
// Cmdline to command line
|
||||
func (c *Cmd) Cmdline() string {
|
||||
func (c *Cmd) Cmdline() string { return comfunc.Cmdline(c.Args) }
|
||||
|
||||
// RawLine raw command line for print show.
|
||||
func (c *Cmd) RawLine() string {
|
||||
if c.PrintLine != "" {
|
||||
return c.PrintLine
|
||||
}
|
||||
return comfunc.Cmdline(c.Args)
|
||||
}
|
||||
|
||||
|
||||
+15
-3
@@ -4,15 +4,27 @@ package cmdr
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gookit/color"
|
||||
"github.com/gookit/goutil/x/ccolor"
|
||||
)
|
||||
|
||||
// PrintCmdline on before exec
|
||||
func PrintCmdline(c *Cmd) {
|
||||
if c.DryRun {
|
||||
color.Yellowln("DRY-RUN>", c.Cmdline())
|
||||
ccolor.Yellowln("DRY-RUN>", c.RawLine())
|
||||
} else {
|
||||
color.Yellowln(">", c.Cmdline())
|
||||
ccolor.Yellowln(">", c.RawLine())
|
||||
}
|
||||
}
|
||||
|
||||
// PrintCmdline2 on before exec
|
||||
func PrintCmdline2(c *Cmd) {
|
||||
if c.Dir != "" {
|
||||
ccolor.Magentaln("> Workdir:", c.Dir)
|
||||
}
|
||||
if c.DryRun {
|
||||
ccolor.Yellowln("DRY-RUN>", c.RawLine())
|
||||
} else {
|
||||
ccolor.Yellowln(">", c.RawLine())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -4,13 +4,13 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/gookit/color"
|
||||
"github.com/gookit/goutil/arrutil"
|
||||
"github.com/gookit/goutil/cliutil/cmdline"
|
||||
"github.com/gookit/goutil/errorx"
|
||||
"github.com/gookit/goutil/maputil"
|
||||
"github.com/gookit/goutil/mathutil"
|
||||
"github.com/gookit/goutil/strutil/textutil"
|
||||
"github.com/gookit/goutil/x/ccolor"
|
||||
)
|
||||
|
||||
// Task struct
|
||||
@@ -226,7 +226,7 @@ func (r *Runner) Run() error {
|
||||
}
|
||||
|
||||
if r.DryRun {
|
||||
color.Infof("DRY-RUN: task#%d execute completed\n\n", i+1)
|
||||
ccolor.Infof("DRY-RUN: task#%d execute completed\n\n", i+1)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ func (r *Runner) RunTask(task *Task) (goon bool) {
|
||||
// do running
|
||||
if err := task.RunWith(r.Params); err != nil {
|
||||
r.Errs[task.ID] = err
|
||||
color.Errorf("Task#%d run error: %s\n", task.Index()+1, err)
|
||||
ccolor.Errorf("Task#%d run error: %s\n", task.Index()+1, err)
|
||||
|
||||
// not ignore error, stop.
|
||||
if !r.IgnoreErr {
|
||||
|
||||
+30
-17
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/gookit/goutil/errorx"
|
||||
"github.com/gookit/goutil/strutil"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// OSVersionInfo 结构体用于存储操作系统版本信息
|
||||
@@ -22,18 +23,42 @@ type OSVersionInfo struct {
|
||||
RevisionNumber uint32
|
||||
}
|
||||
|
||||
// FetchOsVersion Get Windows system version information
|
||||
// cache: 全局变量
|
||||
var stdOv = VersionInfoBySys()
|
||||
|
||||
// OsVersion Get operating system version information
|
||||
func OsVersion() *OSVersionInfo { return stdOv }
|
||||
|
||||
// VersionInfoBySys Get Windows system version information by sys/windows
|
||||
func VersionInfoBySys() *OSVersionInfo {
|
||||
// Get the Windows Version and Build Number
|
||||
var majorVersion, minorVersion, buildNumber = windows.RtlGetNtVersionNumbers()
|
||||
|
||||
return &OSVersionInfo{
|
||||
MajorVersion: uint16(majorVersion),
|
||||
MinorVersion: uint16(minorVersion),
|
||||
BuildNumber: buildNumber,
|
||||
}
|
||||
}
|
||||
|
||||
// OsVersionByParse Get Windows system version information by parse string
|
||||
//
|
||||
// cmdOut eg: "Microsoft Windows [Version 10.0.22631.4391]"
|
||||
func OsVersionByParse(cmdOut string) (*OSVersionInfo, error) {
|
||||
return parseOsVersionString(cmdOut)
|
||||
}
|
||||
|
||||
// OsVersionByVerCmd Get Windows system version information
|
||||
//
|
||||
// 还可用使用dll获取:
|
||||
//
|
||||
// 通过 GetVersion, GetVersionEx 函数获取的信息不准确. win11获取到 6.2.9200, 实际是 10.0.22631
|
||||
func FetchOsVersion() (*OSVersionInfo, error) {
|
||||
func OsVersionByVerCmd() (*OSVersionInfo, error) {
|
||||
// Windows cmd 执行 ver 命令
|
||||
out, err := ShellExec("ver", "cmd")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return parseOsVersionString(out)
|
||||
}
|
||||
|
||||
@@ -47,9 +72,9 @@ func (ov *OSVersionInfo) IsWindows7() bool {
|
||||
return ov.MajorVersion == 6 && ov.MinorVersion == 1
|
||||
}
|
||||
|
||||
// IsWindows8 判断是否为 Windows 8
|
||||
// IsWindows8 判断是否为 Windows 8/8.1
|
||||
func (ov *OSVersionInfo) IsWindows8() bool {
|
||||
return ov.MajorVersion == 6 && ov.MinorVersion == 2
|
||||
return ov.MajorVersion == 6 && (ov.MinorVersion == 2 || ov.MinorVersion == 3)
|
||||
}
|
||||
|
||||
// IsWindows10 判断是否为 Windows 10
|
||||
@@ -129,15 +154,3 @@ func parseOsVersionString(out string) (*OSVersionInfo, error) {
|
||||
return &ovi, nil
|
||||
}
|
||||
|
||||
// 全局变量
|
||||
var stdOv, stdErr = FetchOsVersion()
|
||||
|
||||
// OsVersion Get operating system version information
|
||||
func OsVersion() *OSVersionInfo {
|
||||
return stdOv
|
||||
}
|
||||
|
||||
// OvParseError error on parse os version info
|
||||
func OvParseError() error {
|
||||
return stdErr
|
||||
}
|
||||
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
package sysutil
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// CallerInfo struct
|
||||
type CallerInfo struct {
|
||||
PC uintptr
|
||||
Fc *runtime.Func
|
||||
File string
|
||||
Line int
|
||||
}
|
||||
|
||||
// String convert
|
||||
func (ci *CallerInfo) String() string {
|
||||
return ci.File + ":" + strconv.Itoa(ci.Line)
|
||||
}
|
||||
|
||||
// CallersInfos returns an array of the CallerInfo.
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// cs := sysutil.CallersInfos(3, 2)
|
||||
// for _, ci := range cs {
|
||||
// fc := runtime.FuncForPC(pc)
|
||||
// // maybe need check fc = nil
|
||||
// fnName = fc.Name()
|
||||
// }
|
||||
func CallersInfos(skip, num int, filters ...func(file string, fc *runtime.Func) bool) []*CallerInfo {
|
||||
filterLn := len(filters)
|
||||
callers := make([]*CallerInfo, 0, num)
|
||||
for i := skip; i < skip+num; i++ {
|
||||
pc, file, line, ok := runtime.Caller(i)
|
||||
if !ok {
|
||||
// The breaks below failed to terminate the loop, and we ran off the
|
||||
// end of the call stack.
|
||||
break
|
||||
}
|
||||
|
||||
fc := runtime.FuncForPC(pc)
|
||||
if fc == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if filterLn > 0 && filters[0] != nil {
|
||||
// filter - return false for skip
|
||||
if !filters[0](file, fc) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// collecting
|
||||
callers = append(callers, &CallerInfo{
|
||||
PC: pc,
|
||||
Fc: fc,
|
||||
File: file,
|
||||
Line: line,
|
||||
})
|
||||
}
|
||||
|
||||
return callers
|
||||
}
|
||||
+26
-6
@@ -13,12 +13,23 @@ import (
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
// os names
|
||||
const (
|
||||
Windows = "windows"
|
||||
Linux = "linux"
|
||||
Darwin = "darwin"
|
||||
FreeBSD = "freebsd"
|
||||
)
|
||||
|
||||
// IsMSys msys(MINGW64) env,不一定支持颜色
|
||||
func IsMSys() bool {
|
||||
// "MSYSTEM=MINGW64"
|
||||
return len(os.Getenv("MSYSTEM")) > 0
|
||||
}
|
||||
|
||||
// IsWSL system env
|
||||
func IsWSL() bool { return checkfn.IsWSL() }
|
||||
|
||||
// IsConsole check out is in stderr/stdout/stdin
|
||||
//
|
||||
// Usage:
|
||||
@@ -61,8 +72,8 @@ func Hostname() string {
|
||||
//
|
||||
// eg "/bin/zsh" "/bin/bash".
|
||||
// if onlyName=true, will return "zsh", "bash"
|
||||
func CurrentShell(onlyName bool) (path string) {
|
||||
return comfunc.CurrentShell(onlyName)
|
||||
func CurrentShell(onlyName bool, fallbackShell ...string) string {
|
||||
return comfunc.CurrentShell(onlyName, fallbackShell...)
|
||||
}
|
||||
|
||||
// HasShellEnv has shell env check.
|
||||
@@ -145,9 +156,14 @@ func EnvPaths() []string {
|
||||
return filepath.SplitList(os.Getenv("PATH"))
|
||||
}
|
||||
|
||||
// ToEnvPATH convert []string to $PATH string.
|
||||
func ToEnvPATH(paths []string) string {
|
||||
return strings.Join(paths, string(filepath.ListSeparator))
|
||||
}
|
||||
|
||||
// SearchPathOption settings for SearchPath
|
||||
type SearchPathOption struct {
|
||||
// 限制的扩展名
|
||||
// 限制查找的扩展名(Windows) such as ".exe", ".bat", ".cmd"
|
||||
LimitExt []string
|
||||
}
|
||||
|
||||
@@ -156,14 +172,18 @@ type SearchPathOption struct {
|
||||
// Usage:
|
||||
//
|
||||
// sysutil.SearchPath("go")
|
||||
func SearchPath(keywords string, limit int) []string {
|
||||
func SearchPath(keywords string, limit int, opts ...SearchPathOption) []string {
|
||||
path := os.Getenv("PATH")
|
||||
ptn := "*" + keywords + "*"
|
||||
list := make([]string, 0)
|
||||
|
||||
opt := SearchPathOption{LimitExt: []string{".exe", ".bat", ".cmd"}}
|
||||
if len(opts) > 0 {
|
||||
opt = opts[0]
|
||||
}
|
||||
|
||||
// if windows, will limit with .exe, .bat, .cmd
|
||||
isWindows := IsWindows()
|
||||
winExts := []string{".exe", ".bat", ".cmd"}
|
||||
checked := make(map[string]bool)
|
||||
for _, dir := range filepath.SplitList(path) {
|
||||
// Unix shell semantics: path element "" means "."
|
||||
@@ -183,7 +203,7 @@ func SearchPath(keywords string, limit int) []string {
|
||||
// if windows, will limit with .exe, .bat, .cmd
|
||||
for _, fPath := range matches {
|
||||
fExt := filepath.Ext(fPath)
|
||||
if checkfn.StringsContains(winExts, fExt) {
|
||||
if checkfn.StringsContains(opt.LimitExt, fExt) {
|
||||
continue
|
||||
}
|
||||
list = append(list, fPath)
|
||||
|
||||
+9
-1
@@ -3,7 +3,7 @@ package sysutil
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"github.com/gookit/goutil/goinfo"
|
||||
"github.com/gookit/goutil/x/goinfo"
|
||||
)
|
||||
|
||||
// GoVersion get go runtime version. eg: "1.18.2"
|
||||
@@ -14,6 +14,9 @@ func GoVersion() string {
|
||||
// GoInfo define. alias of goinfo.GoInfo
|
||||
type GoInfo = goinfo.GoInfo
|
||||
|
||||
// CallerInfo define. alias of goinfo.CallerInfo
|
||||
type CallerInfo = goinfo.CallerInfo
|
||||
|
||||
// ParseGoVersion get info by parse `go version` results. alias of goinfo.ParseGoVersion()
|
||||
//
|
||||
// Examples:
|
||||
@@ -33,3 +36,8 @@ func ParseGoVersion(line string) (*GoInfo, error) {
|
||||
func OsGoInfo() (*GoInfo, error) {
|
||||
return goinfo.OsGoInfo()
|
||||
}
|
||||
|
||||
// CallersInfos returns an array of the CallerInfo. can with filters
|
||||
func CallersInfos(skip, num int, filters ...goinfo.CallerFilterFunc) []*CallerInfo {
|
||||
return goinfo.CallersInfos(skip+1, num, filters...)
|
||||
}
|
||||
|
||||
+3
-7
@@ -28,16 +28,12 @@ func BinFile() string {
|
||||
}
|
||||
|
||||
// Open file or url address
|
||||
func Open(fileOrURL string) error {
|
||||
return OpenURL(fileOrURL)
|
||||
}
|
||||
func Open(fileOrURL string) error { return OpenURL(fileOrURL) }
|
||||
|
||||
// OpenBrowser file or url address
|
||||
func OpenBrowser(fileOrURL string) error {
|
||||
return OpenURL(fileOrURL)
|
||||
}
|
||||
func OpenBrowser(fileOrURL string) error { return OpenURL(fileOrURL) }
|
||||
|
||||
// OpenFile opens new browser window for the file path.
|
||||
// OpenFile open files browser window for the file path.
|
||||
func OpenFile(path string) error {
|
||||
fpath, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
|
||||
+4
@@ -1,7 +1,11 @@
|
||||
//go:build darwin
|
||||
package sysutil
|
||||
|
||||
import "os/exec"
|
||||
|
||||
// OsName system name. like runtime.GOOS. allow: linux, windows, darwin
|
||||
const OsName = Darwin
|
||||
|
||||
// IsWin system. linux windows darwin
|
||||
func IsWin() bool { return false }
|
||||
|
||||
|
||||
Generated
Vendored
+4
-5
@@ -1,5 +1,3 @@
|
||||
//go:build !windows && !darwin
|
||||
|
||||
package sysutil
|
||||
|
||||
import (
|
||||
@@ -7,6 +5,9 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// OsName system name. like runtime.GOOS. allow: linux, windows, darwin
|
||||
const OsName = Linux
|
||||
|
||||
// IsWin system. linux windows darwin
|
||||
func IsWin() bool { return false }
|
||||
|
||||
@@ -20,9 +21,7 @@ func IsMac() bool { return false }
|
||||
func IsDarwin() bool { return false }
|
||||
|
||||
// IsLinux system
|
||||
func IsLinux() bool {
|
||||
return true
|
||||
}
|
||||
func IsLinux() bool { return true }
|
||||
|
||||
// There are multiple possible providers to open a browser on linux
|
||||
// One of them is xdg-open, another is x-www-browser, then there's www-browser, etc.
|
||||
+5
-2
@@ -10,6 +10,9 @@ import (
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// OsName system name. like runtime.GOOS. only allow: linux, windows, darwin
|
||||
const OsName = Windows
|
||||
|
||||
// IsWin system. linux windows darwin
|
||||
func IsWin() bool { return true }
|
||||
|
||||
@@ -27,7 +30,7 @@ func IsLinux() bool { return false }
|
||||
|
||||
// Kill a process by pid
|
||||
func Kill(pid int, signal syscall.Signal) error {
|
||||
return errors.New("not support")
|
||||
return errors.New("not support on Windows")
|
||||
}
|
||||
|
||||
// ProcessExists check process exists by pid
|
||||
@@ -35,7 +38,7 @@ func ProcessExists(pid int) bool {
|
||||
panic("TIP: please use sysutil/process.Exists()")
|
||||
}
|
||||
|
||||
// OpenURL Open file or browser URL
|
||||
// OpenURL Open file or browser URL
|
||||
//
|
||||
// - refers https://github.com/pkg/browser
|
||||
//
|
||||
|
||||
+1
-3
@@ -17,9 +17,7 @@ func MustFindUser(uname string) *user.User {
|
||||
}
|
||||
|
||||
// LoginUser must get current user, will panic if error
|
||||
func LoginUser() *user.User {
|
||||
return CurrentUser()
|
||||
}
|
||||
func LoginUser() *user.User { return CurrentUser() }
|
||||
|
||||
// CurrentUser must get current user, will panic if error
|
||||
func CurrentUser() *user.User {
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ func IsAdmin() bool {
|
||||
func ChangeUserByName(newUname string) error {
|
||||
u := MustFindUser(newUname)
|
||||
// syscall.Setlogin(newUname)
|
||||
return ChangeUserUIDGid(strutil.IntOrPanic(u.Uid), strutil.IntOrPanic(u.Gid))
|
||||
return ChangeUserUIDGid(strutil.MustInt(u.Uid), strutil.MustInt(u.Gid))
|
||||
}
|
||||
|
||||
// ChangeUserUidGid change work user by new username uid,gid
|
||||
|
||||
+2
-3
@@ -1,17 +1,16 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package sysutil
|
||||
|
||||
// ChangeUserByName change work user by new username.
|
||||
func ChangeUserByName(newUname string) (err error) {
|
||||
func ChangeUserByName(newUname string) error {
|
||||
return ChangeUserUIDGid(0, 0)
|
||||
}
|
||||
|
||||
// ChangeUserUidGid change work user by new username uid,gid
|
||||
//
|
||||
// Deprecated: use ChangeUserUIDGid instead
|
||||
func ChangeUserUidGid(newUid int, newGid int) (err error) {
|
||||
func ChangeUserUidGid(newUid int, newGid int) error {
|
||||
return ChangeUserUIDGid(newUid, newGid)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user