summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/dcat/main.go31
-rw-r--r--cmd/dgrep/main.go42
-rw-r--r--cmd/dmap/main.go39
-rw-r--r--cmd/drun/main.go35
-rw-r--r--cmd/dserver/main.go2
-rw-r--r--cmd/dtail/main.go62
6 files changed, 68 insertions, 143 deletions
diff --git a/cmd/dcat/main.go b/cmd/dcat/main.go
index 1ab67c2..7690b69 100644
--- a/cmd/dcat/main.go
+++ b/cmd/dcat/main.go
@@ -15,34 +15,29 @@ import (
// The evil begins here.
func main() {
+ var args clients.Args
var cfgFile string
- var connectionsPerCPU int
var debugEnable bool
- var discovery string
var displayVersion bool
- var files string
var noColor bool
- var serversStr string
var quietEnable bool
var sshPort int
- var trustAllHosts bool
- var privateKeyPathFile string
userName := user.Name()
+ flag.BoolVar(&args.TrustAllHosts, "trustAllHosts", false, "Auto trust all unknown host keys")
flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages")
flag.BoolVar(&displayVersion, "version", false, "Display version")
flag.BoolVar(&noColor, "noColor", false, "Disable ANSII terminal colors")
flag.BoolVar(&quietEnable, "quiet", false, "Reduce output")
- flag.BoolVar(&trustAllHosts, "trustAllHosts", false, "Auto trust all unknown host keys")
- flag.IntVar(&connectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently")
+ flag.IntVar(&args.ConnectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently")
flag.IntVar(&sshPort, "port", 2222, "SSH server port")
+ flag.StringVar(&args.Discovery, "discovery", "", "Server discovery method")
+ flag.StringVar(&args.PrivateKeyPathFile, "key", "", "Path to private key")
+ flag.StringVar(&args.ServersStr, "servers", "", "Remote servers to connect")
+ flag.StringVar(&args.UserName, "user", userName, "Your system user name")
+ flag.StringVar(&args.What, "files", "", "File(s) to read")
flag.StringVar(&cfgFile, "cfg", "", "Config file path")
- flag.StringVar(&discovery, "discovery", "", "Server discovery method")
- flag.StringVar(&files, "files", "", "File(s) to read")
- flag.StringVar(&serversStr, "servers", "", "Remote servers to connect")
- flag.StringVar(&userName, "user", userName, "Your system user name")
- flag.StringVar(&privateKeyPathFile, "key", "", "Path to private key")
flag.Parse()
@@ -56,16 +51,6 @@ func main() {
ctx := context.TODO()
logger.Start(ctx, logger.Modes{Debug: debugEnable || config.Common.DebugEnable, Quiet: quietEnable})
- args := clients.Args{
- ConnectionsPerCPU: connectionsPerCPU,
- ServersStr: serversStr,
- Discovery: discovery,
- UserName: userName,
- What: files,
- TrustAllHosts: trustAllHosts,
- PrivateKeyPathFile: privateKeyPathFile,
- }
-
client, err := clients.NewCatClient(args)
if err != nil {
panic(err)
diff --git a/cmd/dgrep/main.go b/cmd/dgrep/main.go
index c08c479..d432135 100644
--- a/cmd/dgrep/main.go
+++ b/cmd/dgrep/main.go
@@ -15,39 +15,33 @@ import (
// The evil begins here.
func main() {
+ var args clients.Args
var cfgFile string
- var connectionsPerCPU int
var debugEnable bool
- var discovery string
var displayVersion bool
- var files string
+ var grep string
var noColor bool
- var regexStr string
- var regexInvert bool
- var serversStr string
var quietEnable bool
var sshPort int
- var trustAllHosts bool
- var privateKeyPathFile string
userName := user.Name()
+ flag.BoolVar(&args.RegexInvert, "invert", false, "Invert regex")
+ flag.BoolVar(&args.TrustAllHosts, "trustAllHosts", false, "Auto trust all unknown host keys")
flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages")
flag.BoolVar(&displayVersion, "version", false, "Display version")
flag.BoolVar(&noColor, "noColor", false, "Disable ANSII terminal colors")
flag.BoolVar(&quietEnable, "quiet", false, "Reduce output")
- flag.BoolVar(&trustAllHosts, "trustAllHosts", false, "Auto trust all unknown host keys")
- flag.IntVar(&connectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently")
+ flag.IntVar(&args.ConnectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently")
flag.IntVar(&sshPort, "port", 2222, "SSH server port")
+ flag.StringVar(&args.Discovery, "discovery", "", "Server discovery method")
+ flag.StringVar(&args.PrivateKeyPathFile, "key", "", "Path to private key")
+ flag.StringVar(&args.RegexStr, "regex", ".", "Regular expression")
+ flag.StringVar(&args.ServersStr, "servers", "", "Remote servers to connect")
+ flag.StringVar(&args.UserName, "user", userName, "Your system user name")
+ flag.StringVar(&args.What, "files", "", "File(s) to read")
flag.StringVar(&cfgFile, "cfg", "", "Config file path")
- flag.StringVar(&discovery, "discovery", "", "Server discovery method")
- flag.StringVar(&files, "files", "", "File(s) to read")
- flag.StringVar(&regexStr, "regex", ".", "Regular expression")
- flag.StringVar(&regexStr, "grep", ".", "Alias for -regex")
- flag.BoolVar(&regexInvert, "invert", false, "Invert regex")
- flag.StringVar(&serversStr, "servers", "", "Remote servers to connect")
- flag.StringVar(&userName, "user", userName, "Your system user name")
- flag.StringVar(&privateKeyPathFile, "key", "", "Path to private key")
+ flag.StringVar(&grep, "grep", "", "Alias for -regex")
flag.Parse()
@@ -61,16 +55,8 @@ func main() {
ctx := context.TODO()
logger.Start(ctx, logger.Modes{Debug: debugEnable || config.Common.DebugEnable, Quiet: quietEnable})
- args := clients.Args{
- ConnectionsPerCPU: connectionsPerCPU,
- ServersStr: serversStr,
- Discovery: discovery,
- UserName: userName,
- What: files,
- TrustAllHosts: trustAllHosts,
- RegexStr: regexStr,
- RegexInvert: regexInvert,
- PrivateKeyPathFile: privateKeyPathFile,
+ if grep != "" {
+ args.RegexStr = grep
}
client, err := clients.NewGrepClient(args)
diff --git a/cmd/dmap/main.go b/cmd/dmap/main.go
index ae16e97..4f6611c 100644
--- a/cmd/dmap/main.go
+++ b/cmd/dmap/main.go
@@ -17,37 +17,34 @@ import (
// The evil begins here.
func main() {
var cfgFile string
- var connectionsPerCPU int
var debugEnable bool
- var discovery string
var displayVersion bool
- var files string
var noColor bool
var queryStr string
- var serversStr string
var quietEnable bool
var sshPort int
- var timeout int
- var trustAllHosts bool
- var privateKeyPathFile string
+
+ args := clients.Args{
+ Mode: omode.MapClient,
+ }
userName := user.Name()
+ flag.BoolVar(&args.TrustAllHosts, "trustAllHosts", false, "Auto trust all unknown host keys")
flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages")
flag.BoolVar(&displayVersion, "version", false, "Display version")
flag.BoolVar(&noColor, "noColor", false, "Disable ANSII terminal colors")
flag.BoolVar(&quietEnable, "quiet", false, "Reduce output")
- flag.BoolVar(&trustAllHosts, "trustAllHosts", false, "Auto trust all unknown host keys")
- flag.IntVar(&connectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently")
+ flag.IntVar(&args.ConnectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently")
+ flag.IntVar(&args.Timeout, "timeout", 0, "Max time dtail server will collect data until disconnection")
flag.IntVar(&sshPort, "port", 2222, "SSH server port")
- flag.IntVar(&timeout, "timeout", 0, "Max time dtail server will collect data until disconnection")
+ flag.StringVar(&args.Discovery, "discovery", "", "Server discovery method")
+ flag.StringVar(&args.PrivateKeyPathFile, "key", "", "Path to private key")
+ flag.StringVar(&args.ServersStr, "servers", "", "Remote servers to connect")
+ flag.StringVar(&args.UserName, "user", userName, "Your system user name")
+ flag.StringVar(&args.What, "files", "", "File(s) to read")
flag.StringVar(&cfgFile, "cfg", "", "Config file path")
- flag.StringVar(&discovery, "discovery", "", "Server discovery method")
- flag.StringVar(&files, "files", "", "File(s) to read")
flag.StringVar(&queryStr, "query", "", "Map reduce query")
- flag.StringVar(&serversStr, "servers", "", "Remote servers to connect")
- flag.StringVar(&userName, "user", userName, "Your system user name")
- flag.StringVar(&privateKeyPathFile, "key", "", "Path to private key")
flag.Parse()
@@ -61,18 +58,6 @@ func main() {
ctx := context.TODO()
logger.Start(ctx, logger.Modes{Debug: debugEnable || config.Common.DebugEnable, Quiet: quietEnable})
- args := clients.Args{
- ConnectionsPerCPU: connectionsPerCPU,
- ServersStr: serversStr,
- Discovery: discovery,
- UserName: userName,
- What: files,
- TrustAllHosts: trustAllHosts,
- Mode: omode.MapClient,
- Timeout: timeout,
- PrivateKeyPathFile: privateKeyPathFile,
- }
-
client, err := clients.NewMaprClient(args, queryStr, clients.DefaultMode)
if err != nil {
panic(err)
diff --git a/cmd/drun/main.go b/cmd/drun/main.go
index 8c78e8f..d18b050 100644
--- a/cmd/drun/main.go
+++ b/cmd/drun/main.go
@@ -17,40 +17,35 @@ import (
// The evil begins here.
func main() {
+ var args clients.Args
var background string
var cfgFile string
var command string
- var connectionsPerCPU int
var debugEnable bool
- var discovery string
var displayVersion bool
var jobName string
var noColor bool
- var serversStr string
var quietEnable bool
var sshPort int
- var timeout int
- var trustAllHosts bool
- var privateKeyPathFile string
userName := user.Name()
+ flag.BoolVar(&args.TrustAllHosts, "trustAllHosts", false, "Auto trust all unknown host keys")
flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages")
flag.BoolVar(&displayVersion, "version", false, "Display version")
flag.BoolVar(&noColor, "noColor", false, "Disable ANSII terminal colors")
flag.BoolVar(&quietEnable, "quiet", false, "Reduce output")
- flag.BoolVar(&trustAllHosts, "trustAllHosts", false, "Auto trust all unknown host keys")
- flag.IntVar(&connectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently")
+ flag.IntVar(&args.ConnectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently")
+ flag.IntVar(&args.Timeout, "timeout", 0, "Command execution timeout")
flag.IntVar(&sshPort, "port", 2222, "SSH server port")
- flag.IntVar(&timeout, "timeout", 0, "Command execution timeout")
+ flag.StringVar(&args.Discovery, "discovery", "", "Server discovery method")
+ flag.StringVar(&args.PrivateKeyPathFile, "key", "", "Path to private key")
+ flag.StringVar(&args.ServersStr, "servers", "", "Remote servers to connect")
+ flag.StringVar(&args.UserName, "user", userName, "Your system user name")
flag.StringVar(&background, "background", "", "Can be one of 'start', 'cancel', 'list' or empty")
flag.StringVar(&cfgFile, "cfg", "", "Config file path")
flag.StringVar(&command, "command", "", "Command to run")
- flag.StringVar(&discovery, "discovery", "", "Server discovery method")
flag.StringVar(&jobName, "name", "", "The job name (if run in background)")
- flag.StringVar(&serversStr, "servers", "", "Remote servers to connect")
- flag.StringVar(&userName, "user", userName, "Your system user name")
- flag.StringVar(&privateKeyPathFile, "key", "", "Path to private key")
flag.Parse()
@@ -64,19 +59,7 @@ func main() {
ctx := context.TODO()
logger.Start(ctx, logger.Modes{Debug: debugEnable || config.Common.DebugEnable, Quiet: quietEnable})
- command, commandArgs := readCommand(command)
- args := clients.Args{
- ConnectionsPerCPU: connectionsPerCPU,
- ServersStr: serversStr,
- Discovery: discovery,
- UserName: userName,
- What: command,
- Arguments: commandArgs,
- TrustAllHosts: trustAllHosts,
- Timeout: timeout,
- PrivateKeyPathFile: privateKeyPathFile,
- }
-
+ args.What, args.Arguments = readCommand(command)
client, err := clients.NewRunClient(args, background, jobName)
if err != nil {
panic(err)
diff --git a/cmd/dserver/main.go b/cmd/dserver/main.go
index 34b983f..d889dc9 100644
--- a/cmd/dserver/main.go
+++ b/cmd/dserver/main.go
@@ -35,9 +35,9 @@ func main() {
flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages")
flag.BoolVar(&displayVersion, "version", false, "Display version")
flag.BoolVar(&noColor, "noColor", false, "Disable ANSII terminal colors")
+ flag.IntVar(&pprof, "pprof", -1, "Start PProf server this port")
flag.IntVar(&shutdownAfter, "shutdownAfter", 0, "Automatically shutdown after so many seconds")
flag.IntVar(&sshPort, "port", 2222, "SSH server port")
- flag.IntVar(&pprof, "pprof", -1, "Start PProf server this port")
flag.StringVar(&cfgFile, "cfg", "", "Config file path")
flag.Parse()
diff --git a/cmd/dtail/main.go b/cmd/dtail/main.go
index 6553808..9aaea49 100644
--- a/cmd/dtail/main.go
+++ b/cmd/dtail/main.go
@@ -23,50 +23,50 @@ import (
func main() {
var cfgFile string
var checkHealth bool
- var connectionsPerCPU int
var debugEnable bool
- var discovery string
- var shutdownAfter int
- var pprof int
var displayVersion bool
- var files string
+ var grep string
var noColor bool
+ var pprof int
var queryStr string
- var regexStr string
- var regexInvert bool
- var serversStr string
var quietEnable bool
+ var shutdownAfter int
var sshPort int
- var timeout int
- var trustAllHosts bool
- var privateKeyPathFile string
+
+ args := clients.Args{
+ Mode: omode.TailClient,
+ }
userName := user.Name()
+ flag.BoolVar(&args.RegexInvert, "invert", false, "Invert regex")
+ flag.BoolVar(&args.TrustAllHosts, "trustAllHosts", false, "Auto trust all unknown host keys")
flag.BoolVar(&checkHealth, "checkHealth", false, "Only check for server health")
flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages")
flag.BoolVar(&displayVersion, "version", false, "Display version")
flag.BoolVar(&noColor, "noColor", false, "Disable ANSII terminal colors")
- flag.IntVar(&shutdownAfter, "shutdownAfter", 3600*24, "Automatically shutdown after so many seconds")
flag.BoolVar(&quietEnable, "quiet", false, "Reduce output")
- flag.BoolVar(&trustAllHosts, "trustAllHosts", false, "Auto trust all unknown host keys")
- flag.IntVar(&connectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently")
- flag.IntVar(&sshPort, "port", 2222, "SSH server port")
- flag.IntVar(&timeout, "timeout", 0, "Max time dtail server will collect data until disconnection")
+ flag.IntVar(&args.ConnectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently")
+ flag.IntVar(&args.Timeout, "timeout", 0, "Max time dtail server will collect data until disconnection")
flag.IntVar(&pprof, "pprof", -1, "Start PProf server this port")
+ flag.IntVar(&shutdownAfter, "shutdownAfter", 3600*24, "Automatically shutdown after so many seconds")
+ flag.IntVar(&sshPort, "port", 2222, "SSH server port")
+ flag.StringVar(&args.Discovery, "discovery", "", "Server discovery method")
+ flag.StringVar(&args.PrivateKeyPathFile, "key", "", "Path to private key")
+ flag.StringVar(&args.RegexStr, "regex", ".", "Regular expression")
+ flag.StringVar(&args.ServersStr, "servers", "", "Remote servers to connect")
+ flag.StringVar(&args.UserName, "user", userName, "Your system user name")
+ flag.StringVar(&args.What, "files", "", "File(s) to read")
flag.StringVar(&cfgFile, "cfg", "", "Config file path")
- flag.StringVar(&discovery, "discovery", "", "Server discovery method")
- flag.StringVar(&files, "files", "", "File(s) to read")
+ flag.StringVar(&grep, "grep", "", "Alias for -regex")
flag.StringVar(&queryStr, "query", "", "Map reduce query")
- flag.StringVar(&regexStr, "regex", ".", "Regular expression")
- flag.StringVar(&regexStr, "grep", ".", "Alias for -regex")
- flag.BoolVar(&regexInvert, "invert", false, "Invert regex")
- flag.StringVar(&serversStr, "servers", "", "Remote servers to connect")
- flag.StringVar(&userName, "user", userName, "Your system user name")
- flag.StringVar(&privateKeyPathFile, "key", "", "Path to private key")
flag.Parse()
+ if grep != "" {
+ args.RegexStr = grep
+ }
+
config.Read(cfgFile, sshPort)
color.Colored = !noColor
@@ -96,20 +96,6 @@ func main() {
go http.ListenAndServe(pprofArgs, nil)
}
- args := clients.Args{
- ConnectionsPerCPU: connectionsPerCPU,
- ServersStr: serversStr,
- Discovery: discovery,
- UserName: userName,
- What: files,
- TrustAllHosts: trustAllHosts,
- RegexStr: regexStr,
- RegexInvert: regexInvert,
- Mode: omode.TailClient,
- Timeout: timeout,
- PrivateKeyPathFile: privateKeyPathFile,
- }
-
var client clients.Client
var err error