Add logout (#13796)

### What problem does this PR solve?

Add command: logout

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-03-26 11:54:23 +08:00
committed by GitHub
parent ebf36950e4
commit e705ac6643
8 changed files with 98 additions and 32 deletions

View File

@@ -110,7 +110,7 @@ func parseHostPort(hostPort string) (string, int, error) {
func ParseConnectionArgs(args []string) (*ConnectionArgs, error) {
// First, scan args to check for help, config file, and admin mode
var configFilePath string
var adminMode bool = false
for i := 0; i < len(args); i++ {
arg := args[i]
if arg == "--help" || arg == "-help" {
@@ -118,6 +118,8 @@ func ParseConnectionArgs(args []string) (*ConnectionArgs, error) {
} else if (arg == "-f" || arg == "--config") && i+1 < len(args) {
configFilePath = args[i+1]
i++
} else if arg == "--admin" {
adminMode = true
}
}
@@ -125,45 +127,48 @@ func ParseConnectionArgs(args []string) (*ConnectionArgs, error) {
var config *ConfigFile
var err error
if configFilePath != "" {
// User specified config file via -f
config, err = LoadConfigFileFromPath(configFilePath)
if err != nil {
return nil, err
}
} else {
// Try default rf.yml
config, err = LoadDefaultConfigFile()
if err != nil {
return nil, err
}
}
// Parse arguments manually to support both short and long forms
// and to handle priority: command line > config file > defaults
// Build result from config file first (if exists), then override with command line flags
result := &ConnectionArgs{}
if !adminMode {
// Only user mode read config file
if configFilePath != "" {
// User specified config file via -f
config, err = LoadConfigFileFromPath(configFilePath)
if err != nil {
return nil, err
}
} else {
// Try default rf.yml
config, err = LoadDefaultConfigFile()
if err != nil {
return nil, err
}
}
// Apply config file values first (lower priority)
if config != nil {
// Parse host:port from config file
if config.Host != "" {
h, port, err := parseHostPort(config.Host)
if err != nil {
return nil, fmt.Errorf("invalid host in config file: %v", err)
}
result.Host = h
result.Port = port
}
result.UserName = config.UserName
result.Password = config.Password
result.APIToken = config.APIToken
}
}
// Get non-flag arguments (command to execute)
var nonFlagArgs []string
// Apply config file values first (lower priority)
if config != nil {
// Parse host:port from config file
if config.Host != "" {
h, port, err := parseHostPort(config.Host)
if err != nil {
return nil, fmt.Errorf("invalid host in config file: %v", err)
}
result.Host = h
result.Port = port
}
result.UserName = config.UserName
result.Password = config.Password
result.APIToken = config.APIToken
}
// Override with command line flags (higher priority)
// Handle both short and long forms manually
for i := 0; i < len(args); i++ {