API: Improve cli usage descriptions (#4401)

This commit is contained in:
Bill Zhong 2025-02-18 05:06:39 -03:30 committed by GitHub
parent 958b13ebb5
commit a1714cc4ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 194 additions and 114 deletions

View File

@ -13,25 +13,20 @@ import (
var cmdBalancerInfo = &base.Command{ var cmdBalancerInfo = &base.Command{
CustomFlags: true, CustomFlags: true,
UsageLine: "{{.Exec}} api bi [--server=127.0.0.1:8080] [balancer]...", UsageLine: "{{.Exec}} api bi [--server=127.0.0.1:8080] [balancer]...",
Short: "balancer information", Short: "Retrieve balancer information",
Long: ` Long: `
Get information of specified balancers, including health, strategy Retrieve information of specified balancers, including health, strategy and selecting.
and selecting. If no balancer tag specified, get information of If no balancer tag specified, information for all balancers is returned.
all balancers.
> Make sure you have "RoutingService" set in "config.api.services" > Ensure that "RoutingService" is enabled under "config.api.services" in the server configuration.
of server config.
Arguments: Arguments:
-json
Use json output.
-s, -server <server:port> -s, -server <server:port>
The API server address. Default 127.0.0.1:8080 The API server address. Default 127.0.0.1:8080
-t, -timeout <seconds> -t, -timeout <seconds>
Timeout seconds to call API. Default 3 Timeout in seconds for calling API. Default 3
Example: Example:

View File

@ -7,31 +7,27 @@ import (
var cmdBalancerOverride = &base.Command{ var cmdBalancerOverride = &base.Command{
CustomFlags: true, CustomFlags: true,
UsageLine: "{{.Exec}} api bo [--server=127.0.0.1:8080] <-b balancer> outboundTag", UsageLine: "{{.Exec}} api bo [--server=127.0.0.1:8080] <-b balancer> outboundTag <-r>",
Short: "balancer override", Short: "Override balancer",
Long: ` Long: `
Override a balancer's selection. Override the selection target of a balancer.
> Make sure you have "RoutingService" set in "config.api.services" > Ensure that the "RoutingService" is properly configured under "config.api.services" in the server configuration.
of server config.
Once a balancer's selecting is overridden: Once the balancer's selection is overridden:
- The balancer's selection result will always be outboundTag - The balancer's selection result will always be outboundTag
Arguments: Arguments:
-r, -remove -s, -server <server:port>
Remove the overridden
-r, -remove
Remove the override
-s, -server
The API server address. Default 127.0.0.1:8080 The API server address. Default 127.0.0.1:8080
-t, -timeout -t, -timeout <seconds>
Timeout seconds to call API. Default 3 Timeout in seconds for calling API. Default 3
-r, -remove
Remove the existing override.
Example: Example:

View File

@ -8,20 +8,28 @@ import (
var cmdInboundUser = &base.Command{ var cmdInboundUser = &base.Command{
CustomFlags: true, CustomFlags: true,
UsageLine: "{{.Exec}} api inbounduser [--server=127.0.0.1:8080] -tag=tag [-email=email]", UsageLine: "{{.Exec}} api inbounduser [--server=127.0.0.1:8080] -tag=tag [-email=email]",
Short: "Get Inbound User", Short: "Retrieve inbound user(s)",
Long: ` Long: `
Get User info from an inbound. Get User info from an inbound.
Arguments: Arguments:
-s, -server
-s, -server <server:port>
The API server address. Default 127.0.0.1:8080 The API server address. Default 127.0.0.1:8080
-t, -timeout
Timeout seconds to call API. Default 3 -t, -timeout <seconds>
Timeout in seconds for calling API. Default 3
-tag -tag
Inbound tag Inbound tag
-email
User email. If email is not given, will get all users -email
The user's email address. If not provided, all users will be retrieved.
Example: Example:
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -tag="tag name" -email="xray@love.com"
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -tag="tag name"
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -tag="tag name" -email="xray@love.com"
`, `,
Run: executeInboundUser, Run: executeInboundUser,
} }

View File

@ -8,18 +8,24 @@ import (
var cmdInboundUserCount = &base.Command{ var cmdInboundUserCount = &base.Command{
CustomFlags: true, CustomFlags: true,
UsageLine: "{{.Exec}} api inboundusercount [--server=127.0.0.1:8080] -tag=tag", UsageLine: "{{.Exec}} api inboundusercount [--server=127.0.0.1:8080] -tag=tag",
Short: "Get Inbound User Count", Short: "Retrieve inbound user count",
Long: ` Long: `
Get User count from an inbound. Retrieve the user count for a specified inbound tag.
Arguments: Arguments:
-s, -server
-s, -server <server:port>
The API server address. Default 127.0.0.1:8080 The API server address. Default 127.0.0.1:8080
-t, -timeout
Timeout seconds to call API. Default 3 -t, -timeout <seconds>
Timeout in seconds for calling API. Default 3
-tag -tag
Inbound tag Inbound tag
Example: Example:
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -tag="tag name"
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -tag="tag name"
`, `,
Run: executeInboundUserCount, Run: executeInboundUserCount,
} }

View File

@ -15,13 +15,18 @@ var cmdAddInbounds = &base.Command{
Short: "Add inbounds", Short: "Add inbounds",
Long: ` Long: `
Add inbounds to Xray. Add inbounds to Xray.
Arguments: Arguments:
-s, -server
-s, -server <server:port>
The API server address. Default 127.0.0.1:8080 The API server address. Default 127.0.0.1:8080
-t, -timeout
Timeout seconds to call API. Default 3 -t, -timeout <seconds>
Timeout in seconds for calling API. Default 3
Example: Example:
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 c1.json c2.json
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 c1.json c2.json
`, `,
Run: executeAddInbounds, Run: executeAddInbounds,
} }

View File

@ -14,13 +14,18 @@ var cmdRemoveInbounds = &base.Command{
Short: "Remove inbounds", Short: "Remove inbounds",
Long: ` Long: `
Remove inbounds from Xray. Remove inbounds from Xray.
Arguments: Arguments:
-s, -server
-s, -server <server:port>
The API server address. Default 127.0.0.1:8080 The API server address. Default 127.0.0.1:8080
-t, -timeout
Timeout seconds to call API. Default 3 -t, -timeout <seconds>
Timeout in seconds for calling API. Default 3
Example: Example:
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 c1.json "tag name"
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 c1.json "tag name"
`, `,
Run: executeRemoveInbounds, Run: executeRemoveInbounds,
} }

View File

@ -11,11 +11,18 @@ var cmdRestartLogger = &base.Command{
Short: "Restart the logger", Short: "Restart the logger",
Long: ` Long: `
Restart the logger of Xray. Restart the logger of Xray.
Arguments: Arguments:
-s, -server
-s, -server <server:port>
The API server address. Default 127.0.0.1:8080 The API server address. Default 127.0.0.1:8080
-t, -timeout
Timeout seconds to call API. Default 3 -t, -timeout <seconds>
Timeout in seconds for calling API. Default 3
Example:
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080
`, `,
Run: executeRestartLogger, Run: executeRestartLogger,
} }

View File

@ -15,13 +15,18 @@ var cmdAddOutbounds = &base.Command{
Short: "Add outbounds", Short: "Add outbounds",
Long: ` Long: `
Add outbounds to Xray. Add outbounds to Xray.
Arguments: Arguments:
-s, -server
-s, -server <server:port>
The API server address. Default 127.0.0.1:8080 The API server address. Default 127.0.0.1:8080
-t, -timeout
Timeout seconds to call API. Default 3 -t, -timeout <seconds>
Timeout in seconds for calling API. Default 3
Example: Example:
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 c1.json c2.json
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 c1.json c2.json
`, `,
Run: executeAddOutbounds, Run: executeAddOutbounds,
} }

View File

@ -14,13 +14,18 @@ var cmdRemoveOutbounds = &base.Command{
Short: "Remove outbounds", Short: "Remove outbounds",
Long: ` Long: `
Remove outbounds from Xray. Remove outbounds from Xray.
Arguments: Arguments:
-s, -server
-s, -server <server:port>
The API server address. Default 127.0.0.1:8080 The API server address. Default 127.0.0.1:8080
-t, -timeout
Timeout seconds to call API. Default 3 -t, -timeout <seconds>
Timeout in seconds for calling API. Default 3
Example: Example:
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 c1.json "tag name"
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 c1.json "tag name"
`, `,
Run: executeRemoveOutbounds, Run: executeRemoveOutbounds,
} }

View File

@ -16,16 +16,21 @@ var cmdAddRules = &base.Command{
Short: "Add routing rules", Short: "Add routing rules",
Long: ` Long: `
Add routing rules to Xray. Add routing rules to Xray.
Arguments: Arguments:
-s, -server
-s, -server <server:port>
The API server address. Default 127.0.0.1:8080 The API server address. Default 127.0.0.1:8080
-t, -timeout
-t, -timeout <seconds>
Timeout seconds to call API. Default 3 Timeout seconds to call API. Default 3
-append -append
append or replace config. Default false Append to the existing configuration instead of replacing it. Default false
Example: Example:
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 c1.json c2.json
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 c1.json c2.json
`, `,
Run: executeAddRules, Run: executeAddRules,
} }

View File

@ -9,17 +9,22 @@ import (
var cmdRemoveRules = &base.Command{ var cmdRemoveRules = &base.Command{
CustomFlags: true, CustomFlags: true,
UsageLine: "{{.Exec}} api rmrules [--server=127.0.0.1:8080] ruleTag1 ruleTag2...", UsageLine: "{{.Exec}} api rmrules [--server=127.0.0.1:8080] [ruleTag]...",
Short: "Remove routing rules by ruleTag", Short: "Remove routing rules by ruleTag",
Long: ` Long: `
Remove routing rules by ruleTag from Xray. Remove routing rules by ruleTag from Xray.
Arguments: Arguments:
-s, -server
-s, -server <server:port>
The API server address. Default 127.0.0.1:8080 The API server address. Default 127.0.0.1:8080
-t, -timeout
Timeout seconds to call API. Default 3 -t, -timeout <seconds>
Timeout in seconds for calling API. Default 3
Example: Example:
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 ruleTag1 ruleTag2
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 ruleTag1 ruleTag2
`, `,
Run: executeRemoveRules, Run: executeRemoveRules,
} }

View File

@ -14,25 +14,34 @@ import (
var cmdSourceIpBlock = &base.Command{ var cmdSourceIpBlock = &base.Command{
CustomFlags: true, CustomFlags: true,
UsageLine: "{{.Exec}} api sib [--server=127.0.0.1:8080] -outbound=blocked -inbound=socks 1.2.3.4", UsageLine: "{{.Exec}} api sib [--server=127.0.0.1:8080] -outbound=blocked -inbound=socks 1.2.3.4",
Short: "Drop connections by source ip", Short: "Block connections by source IP",
Long: ` Long: `
Drop connections by source ip. Block connections by source IP address.
Arguments: Arguments:
-s, -server
-s, -server <server:port>
The API server address. Default 127.0.0.1:8080 The API server address. Default 127.0.0.1:8080
-t, -timeout
Timeout seconds to call API. Default 3 -t, -timeout <seconds>
Timeout in seconds for calling API. Default 3
-outbound -outbound
route traffic to specific outbound. Specifies the outbound tag.
-inbound -inbound
target traffig from specific inbound. Specifies the inbound tag.
-ruletag -ruletag
set ruleTag. Default sourceIpBlock The ruleTag. Default sourceIpBlock
-reset -reset
remove ruletag and apply new source IPs. Default false remove ruletag and apply new source IPs. Default false
Example: Example:
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 c1.json c2.json
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -outbound=blocked -inbound=socks 1.2.3.4
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -outbound=blocked -inbound=socks 1.2.3.4 -reset
`, `,
Run: executeSourceIpBlock, Run: executeSourceIpBlock,
} }

View File

@ -8,19 +8,26 @@ import (
var cmdGetStats = &base.Command{ var cmdGetStats = &base.Command{
CustomFlags: true, CustomFlags: true,
UsageLine: "{{.Exec}} api stats [--server=127.0.0.1:8080] [-name '']", UsageLine: "{{.Exec}} api stats [--server=127.0.0.1:8080] [-name '']",
Short: "Get statistics", Short: "Retrieve statistics",
Long: ` Long: `
Get statistics from Xray. Retrieve the statistics from Xray.
Arguments: Arguments:
-s, -server
-s, -server <server:port>
The API server address. Default 127.0.0.1:8080 The API server address. Default 127.0.0.1:8080
-t, -timeout
Timeout seconds to call API. Default 3 -t, -timeout <seconds>
Timeout in seconds for calling API. Default 3
-name -name
Name of the stat counter. Name of the counter.
-reset -reset
Reset the counter to fetching its value. Reset the counter after fetching their values. Default false
Example: Example:
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -name "inbound>>>statin>>>traffic>>>downlink" {{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -name "inbound>>>statin>>>traffic>>>downlink"
`, `,
Run: executeGetStats, Run: executeGetStats,

View File

@ -7,21 +7,25 @@ import (
var cmdOnlineStats = &base.Command{ var cmdOnlineStats = &base.Command{
CustomFlags: true, CustomFlags: true,
UsageLine: "{{.Exec}} api statsonline [--server=127.0.0.1:8080] [-name '']", UsageLine: "{{.Exec}} api statsonline [--server=127.0.0.1:8080] [-email '']",
Short: "Get online user", Short: "Retrieve the online session count for a user",
Long: ` Long: `
Get statistics from Xray. Retrieve the current number of active sessions for a user from Xray.
Arguments: Arguments:
-s, -server
-s, -server <server:port>
The API server address. Default 127.0.0.1:8080 The API server address. Default 127.0.0.1:8080
-t, -timeout
Timeout seconds to call API. Default 3 -t, -timeout <seconds>
Timeout in seconds for calling API. Default 3
-email -email
email of the user. The user's email address.
-reset
Reset the counter to fetching its value.
Example: Example:
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -email "user1@test.com"
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -email "xray@love.com"
`, `,
Run: executeOnlineStats, Run: executeOnlineStats,
} }

View File

@ -7,21 +7,25 @@ import (
var cmdOnlineStatsIpList = &base.Command{ var cmdOnlineStatsIpList = &base.Command{
CustomFlags: true, CustomFlags: true,
UsageLine: "{{.Exec}} api statsonlineiplist [--server=127.0.0.1:8080] [-name '']", UsageLine: "{{.Exec}} api statsonlineiplist [--server=127.0.0.1:8080] [-email '']",
Short: "Get online user ips list and access times", Short: "Retrieve a user's online IP addresses and access times",
Long: ` Long: `
Get statistics from Xray. Retrieve the online IP addresses and corresponding access timestamps for a user from Xray.
Arguments: Arguments:
-s, -server
-s, -server <server:port>
The API server address. Default 127.0.0.1:8080 The API server address. Default 127.0.0.1:8080
-t, -timeout
Timeout seconds to call API. Default 3 -t, -timeout <seconds>
Timeout in seconds for calling API. Default 3
-email -email
email of the user. The user's email address.
-reset
Reset the counter to fetching its value (not used).
Example: Example:
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -email "user1@test.com"
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -email "xray@love.com"
`, `,
Run: executeOnlineStatsIpList, Run: executeOnlineStatsIpList,
} }

View File

@ -11,16 +11,23 @@ var cmdQueryStats = &base.Command{
Short: "Query statistics", Short: "Query statistics",
Long: ` Long: `
Query statistics from Xray. Query statistics from Xray.
Arguments: Arguments:
-s, -server
-s, -server <server:port>
The API server address. Default 127.0.0.1:8080 The API server address. Default 127.0.0.1:8080
-t, -timeout
Timeout seconds to call API. Default 3 -t, -timeout <seconds>
Timeout in seconds for calling API. Default 3
-pattern -pattern
Pattern of the query. Filter pattern for the statistics query.
-reset -reset
Reset the counter to fetching its value. Reset the counter after fetching their values. Default false
Example: Example:
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -pattern "counter_" {{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -pattern "counter_"
`, `,
Run: executeQueryStats, Run: executeQueryStats,

View File

@ -8,14 +8,21 @@ import (
var cmdSysStats = &base.Command{ var cmdSysStats = &base.Command{
CustomFlags: true, CustomFlags: true,
UsageLine: "{{.Exec}} api statssys [--server=127.0.0.1:8080]", UsageLine: "{{.Exec}} api statssys [--server=127.0.0.1:8080]",
Short: "Get system statistics", Short: "Retrieve system statistics",
Long: ` Long: `
Get system statistics from Xray. Retrieve system statistics from Xray.
Arguments: Arguments:
-s, -server
-s, -server <server:port>
The API server address. Default 127.0.0.1:8080 The API server address. Default 127.0.0.1:8080
-t, -timeout
Timeout seconds to call API. Default 3 -t, -timeout <seconds>
Timeout in seconds for calling API. Default 3
Example:
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080
`, `,
Run: executeSysStats, Run: executeSysStats,
} }