Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ThisBuild / organization := "app.softnetwork"

name := "softclient4es"

ThisBuild / version := "0.20.1"
ThisBuild / version := "0.20.2-SNAPSHOT"

ThisBuild / scalaVersion := scala213

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/resources/softnetwork-elastic.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ elastic {
port = 9200
port = ${?ELASTIC_PORT}

method = "noauth" # Options: "noauth", "basic", "api-key", "bearer-token"
# No default: absent unless ELASTIC_AUTH_METHOD is set, so ElasticCredentials
# auto-detects the method from the supplied credentials (basic / api-key / bearer).
method = ${?ELASTIC_AUTH_METHOD}

username = ""
Expand Down
167 changes: 1 addition & 166 deletions core/src/main/scala/app/softnetwork/elastic/client/Cli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object Cli extends App {
implicit val ec: ExecutionContext = system.dispatcher

// Parse command line arguments
val config = parseArgs(args)
val config = CliConfig.parseArgs(args)

try {
val gateway = ElasticClientFactory.createWithMonitoring(config.elasticConfig)
Expand Down Expand Up @@ -62,169 +62,4 @@ object Cli extends App {
// Cleanup
system.terminate()
}

// ==================== Argument Parsing ====================

private def parseArgs(args: Array[String]): CliConfig = {
var scheme = "http"
var host = "localhost"
var port = 9200
var username: Option[String] = None
var password: Option[String] = None
var apiKey: Option[String] = None
var bearerToken: Option[String] = None
var executeFile: Option[String] = None
var executeCommand: Option[String] = None
var promptPassword = false

var i = 0
while (i < args.length) {
args(i) match {
case "-s" | "--scheme" =>
scheme = args(i + 1)
i += 2

case "-h" | "--host" =>
host = args(i + 1)
i += 2

case "-p" | "--port" =>
port = args(i + 1).toInt
i += 2

case "-u" | "--username" =>
username = Some(args(i + 1))
i += 2

case "-P" | "--password" =>
password = Some(args(i + 1))
i += 2

case "-W" =>
promptPassword = true
i += 1

case "-k" | "--api-key" =>
apiKey = Some(args(i + 1))
i += 2

case "-b" | "--bearer-token" =>
bearerToken = Some(args(i + 1))
i += 2

case "-f" | "--file" =>
executeFile = Some(args(i + 1))
i += 2

case "-c" | "--command" =>
executeCommand = Some(args(i + 1))
i += 2

case "--help" =>
printUsage()
System.exit(0)

case unknown =>
System.err.println(s"Unknown argument: $unknown")
printUsage()
System.exit(1)
}
}

if (promptPassword) {
val console = System.console()
if (console == null) {
System.err.println("Error: -W requires an interactive terminal")
System.exit(1)
}
System.err.print("Enter password: ")
System.err.flush()
password = Some(new String(console.readPassword()))
}

CliConfig(
scheme,
host,
port,
username,
password,
apiKey,
bearerToken,
executeFile,
executeCommand
)
}

private def printUsage(): Unit = {
println(
"""
|Elasticsearch SQL CLI
|
|Usage:
| softclient4es [OPTIONS]
|
|Options:
| -s, --scheme <scheme> Connection scheme (http or https, default: http)
| -h, --host <host> Elasticsearch host (default: localhost)
| -p, --port <port> Elasticsearch port (default: 9200)
| -u, --username <user> Username for authentication
| -P, --password <pass> Password for authentication
| -W Prompt for password interactively (input not echoed)
| -k, --api-key <key> API key for authentication
| -b, --bearer-token <token> Bearer token for authentication
| -f, --file <path> Execute SQL from file and exit
| -c, --command <sql> Execute SQL command and exit
| --help Show this help message
|
|Examples:
| # Start interactive REPL
| softclient4es
|
| # Connect to remote host
| softclient4es -h prod-es.example.com -p 9200
|
| # Execute SQL file
| softclient4es -f queries.sql
|
| # Execute single command
| softclient4es -c "SELECT * FROM users LIMIT 10"
|
|Interactive Commands:
| help (\h) Display help information
| quit (\q) Exit the REPL
| exit (\q) Exit the REPL
| history Display command history
| clear Clear the screen
| timing Toggle timing display ON/OFF
| format Set or show output format
| timeout Set or show query timeout
|
|
|Table Commands:
| tables (\t) List all tables
| \st <table> Show table details
| \ct <table> Show table ddl
| \dt <table> Describe table schema
|
|Pipeline Commands:
| pipelines (\p) List all pipelines
| \sp <pipeline> Show pipeline details
| \cp <pipeline> Show pipeline ddl
| \dp <pipeline> Describe pipeline schema
|
|Watcher Commands:
| watchers (\w) List all watchers
| \sw <watcher> Show watcher status
|
|Policy Commands:
| policies (\pol) List all enrich policies
| \sl <policy> Show enrich policy details
|
|Stream Commands:
| consume (\c) Consume streaming results from last query
| stream (\s) Show stream status
| cancel (\x) Cancel active stream
|""".stripMargin
)
}
}
Loading
Loading