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
115 changes: 68 additions & 47 deletions bin/completion/_cql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# -------
#
# * Robinhuett <https://github.com/Robinhuett>
# * Auxten <auxtenwpc#gmail.com>
# * Auxten <[email protected]>
#
# ------------------------------------------------------------------------------

Expand All @@ -21,135 +21,156 @@ _cql_dsn() {
_cql_args() {
case $words[1] in
(help)
_arguments '*:help:(generate console create drop wallet transfer grant mirror explorer adapter idminer rpc
)'
_arguments '*:help:(generate console create drop wallet transfer grant mirror explorer adapter idminer rpc)'
;;
(generate)
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
'-bypass-signature[Disable signature sign and verify, for testing]' \
_arguments '-bypass-signature[Disable signature sign and verify, for testing]' \
'-help[Show help message]' \
'-no-password[Use empty password for master key]' \
'-password=-[Master key]:name: ' \
'-with-password[Enter the passphrase for private.key]' \
'-password=-[Passphrase for encrypting private.key]:name: ' \
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
'-private=-[Generate config using an existing private key]:name: ' \
'-source=-[Generate config using the specified config template]:name: ' \
'-miner=-[Generate miner config with specified miner address]:name: ' \
'*:arguments:(config public)'
;;
(console)
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
'-bypass-signature[Disable signature sign and verify, for testing]' \
'-help[Show help message]' \
'-no-password[Use empty password for master key]' \
'-password=-[Master key]:name: ' \
'-with-password[Enter the passphrase for private.key]' \
'-password=-[Passphrase for encrypting private.key]:name: ' \
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
'-adapter=-[Address to serve a database chain adapter]:adapter_addr: ' \
'-command=-[Run only single command and exit]:cmd: ' \
'-dsn=-[Database url]:dsn:_cql_dsn' \
'-explorer=-[Address serve a database chain explorer]:explorer_addr: ' \
'-file=-[Execute commands from file and exit]:_files' \
'-no-rc[Do not read start up file]' \
'-out=-[Record stdout to file]:out_file:_files' \
'-single-transaction[Execute as a single transaction (if non-interactive)]' \
'-variable=-[Set variable]:var: '
'-variable=-[Set variable]:var: ' \
'1:Database ID:_cql_dsn '
;;
(create)
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
'-bypass-signature[Disable signature sign and verify, for testing]' \
'-help[Show help message]' \
'-no-password[Use empty password for master key]' \
'-password=-[Master key]:name: ' \
'-with-password[Enter the passphrase for private.key]' \
'-password=-[Passphrase for encrypting private.key]:name: ' \
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
'-wait-tx-confirm[Wait for transaction confirmation]'
'-wait-tx-confirm[Wait for transaction confirmation]' \
'-db-advance-payment=-[Customized advance payment]:var: ' \
'-db-consistency-level=-[Consistency level, node*consistency_level is the node count to perform strong consistency]:var: ' \
'-db-encrypt-key=-[Encryption key for persistence data]:var: ' \
'-db-eventual-consistency=-[Use eventual consistency to sync among miner nodes]:var: ' \
'-db-gas-price=-[Customized gas price]:var: ' \
'-db-isolation-level=-[Isolation level in a single node]:var: ' \
'-db-load-avg-per-cpu=-[Minimum idle CPU requirement, 0 for none]:var: ' \
'-db-memory=-[Minimum memory requirement, 0 for none]:var: ' \
'-db-node=-[Target node count]:var: ' \
'-db-space=-[Minimum disk space requirement, 0 for none]:var: ' \
'-db-target-miners=-[List of target miner addresses(separated by ',')]:var: '
;;
(drop)
_arguments -C '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
_arguments -C '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
'-bypass-signature[Disable signature sign and verify, for testing]' \
'-help[Show help message]' \
'-no-password[Use empty password for master key]' \
'-password=-[Master key]:name: ' \
'-with-password[Enter the passphrase for private.key]' \
'-password=-[Passphrase for encrypting private.key]:name: ' \
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
'-wait-tx-confirm[Wait for transaction confirmation]' \
'1:Database ID:_cql_dsn '
;;
(wallet)
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
'-bypass-signature[Disable signature sign and verify, for testing]' \
'-help[Show help message]' \
'-no-password[Use empty password for master key]' \
'-password=-[Master key]:name: ' \
'-with-password[Enter the passphrase for private.key]' \
'-password=-[Passphrase for encrypting private.key]:name: ' \
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
'-balance=-[Get specific token balance of current account]:token_type:(Particle Wave All)'
'-dsn=-[Database url]:dsn:_cql_dsn' \
'-token=-[Get specific token balance of current account, e.g. Particle, Wave, All]:token_type:(Particle Wave All)'
;;
(transfer)
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
'-bypass-signature[Disable signature sign and verify, for testing]' \
'-help[Show help message]' \
'-no-password[Use empty password for master key]' \
'-password=-[Master key]:name: ' \
'-with-password[Enter the passphrase for private.key]' \
'-password=-[Passphrase for encrypting private.key]:name: ' \
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
'-wait-tx-confirm[Wait for transaction confirmation]'
'-wait-tx-confirm[Wait for transaction confirmation]' \
'-amount=-[Token account to transfer]:var: ' \
'-to-dsn=-[Target database dsn to transfer token]:dsn:_cql_dsn' \
'-to-user=-[Target address of an user account to transfer token]:var: ' \
'-token=-[Token type to transfer, e.g. Particle, Wave]:token_type:(Particle Wave)'
;;
(grant)
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
'-bypass-signature[Disable signature sign and verify, for testing]' \
'-help[Show help message]' \
'-no-password[Use empty password for master key]' \
'-password=-[Master key]:name: ' \
'-with-password[Enter the passphrase for private.key]' \
'-password=-[Passphrase for encrypting private.key]:name: ' \
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
'-wait-tx-confirm[Wait for transaction confirmation]'
'-to-dsn=-[Target database dsn to transfer token]:dsn:_cql_dsn' \
'-to-user=-[Target address of an user account to transfer token]:var: ' \
'-wait-tx-confirm[Wait for transaction confirmation]' \
'-perm=-[Permission type struct for grant]:name: '
;;
(mirror)
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
'-bypass-signature[Disable signature sign and verify, for testing]' \
'-help[Show help message]' \
'-no-password[Use empty password for master key]' \
'-password=-[Master key]:name: ' \
'-with-password[Enter the passphrase for private.key]' \
'-password=-[Passphrase for encrypting private.key]:name: ' \
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
'-bg-log-level=-[Background log level]:bg_log_level:(trace debug info warning error fatal panic)' \
'-tmp-path=-[Background service temp file path, use os.TempDir for default]:tmp_path:_files' \
'1:Database ID:_cql_dsn ' \
'2:Listen Addr:'
;;
(explorer)
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
'-bypass-signature[Disable signature sign and verify, for testing]' \
'-help[Show help message]' \
'-no-password[Use empty password for master key]' \
'-password=-[Master key]:name: ' \
'-with-password[Enter the passphrase for private.key]' \
'-password=-[Passphrase for encrypting private.key]:name: ' \
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
'-bg-log-level=-[Background log level]:bg_log_level:(trace debug info warning error fatal panic)' \
'-tmp-path=-[Background service temp file path, use os.TempDir for default]:tmp_path:_files' \
'1:Listen Addr:'
;;
(adapter)
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
'-bypass-signature[Disable signature sign and verify, for testing]' \
'-help[Show help message]' \
'-no-password[Use empty password for master key]' \
'-password=-[Master key]:name: ' \
'-with-password[Enter the passphrase for private.key]' \
'-password=-[Passphrase for encrypting private.key]:name: ' \
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
'-bg-log-level=-[Background log level]:bg_log_level:(trace debug info warning error fatal panic)' \
'-tmp-path=-[Background service temp file path, use os.TempDir for default]:tmp_path:_files' \
'-mirror=-[Mirror server for adapter to query]:' \
'1:Listen Addr:'
;;
(idminer)
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
'-bypass-signature[Disable signature sign and verify, for testing]' \
'-help[Show help message]' \
'-no-password[Use empty password for master key]' \
'-password=-[Master key]:name: ' \
'-with-password[Enter the passphrase for private.key]' \
'-password=-[Passphrase for encrypting private.key]:name: ' \
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
'-difficulty=-[Difficulty for miner to mine nodes and generating nonce (default 24)]:difficulty: ' \
'-loop[Keep mining until interrupted]'
;;
(rpc)
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
'-bypass-signature[Disable signature sign and verify, for testing]' \
'-help[Show help message]' \
'-no-password[Use empty password for master key]' \
'-password=-[Master key]:name: ' \
'-with-password[Enter the passphrase for private.key]' \
'-password=-[Passphrase for encrypting private.key]:name: ' \
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
'-wait-tx-confirm[Wait for transaction confirmation]' \
'-bp[Call block producer node]' \
'-endpoint=-[RPC endpoint Node ID to do test call]:' \
'-wait-tx-confirm[Wait for transaction confirmation]' \
'-name=-[RPC name to do test call]:' \
'-req=-[RPC request to do test call, in json format]:'
;;
Expand Down
6 changes: 3 additions & 3 deletions bin/docker-entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ blockproducer)
exec /app/cqld -config "${COVENANT_CONF}" -metric-web "${METRIC_WEB_ADDR}" "${@}"
;;
observer)
exec /app/cql explorer -config "${COVENANT_CONF}" -no-password "${COVENANTSQL_OBSERVER_ADDR}" "${@}"
exec /app/cql explorer -config "${COVENANT_CONF}" "${COVENANTSQL_OBSERVER_ADDR}" "${@}"
;;
adapter)
exec /app/cql adapter -config "${COVENANT_CONF}" -no-password "${COVENANTSQL_ADAPTER_ADDR}" "${@}"
exec /app/cql adapter -config "${COVENANT_CONF}" "${COVENANTSQL_ADAPTER_ADDR}" "${@}"
;;
mysql-adapter)
exec /app/cql-mysql-adapter -config "${COVENANT_CONF}" "${@}"
;;
cli)
exec /app/cql console -config ${COVENANT_CONF} -no-password "${@}"
exec /app/cql console -config ${COVENANT_CONF} "${@}"
;;
faucet)
exec /app/cql-faucet -config ${COVENANT_CONF} "${@}"
Expand Down
2 changes: 1 addition & 1 deletion client/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ func registerNode() (err error) {
}

if nodeInfo.Role != proto.Leader && nodeInfo.Role != proto.Follower {
log.Infof("Register self to blockproducer: %v", conf.GConf.BP.NodeID)
log.Infof("Self register to blockproducer: %v", conf.GConf.BP.NodeID)
err = rpc.PingBP(nodeInfo, conf.GConf.BP.NodeID)
}

Expand Down
10 changes: 8 additions & 2 deletions cmd/cql/internal/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package internal

import (
"context"
"flag"
"time"

"github.com/CovenantSQL/CovenantSQL/sqlchain/adapter"
Expand All @@ -38,6 +39,9 @@ Adapter serves a SQLChain adapter.
e.g.
cql adapter 127.0.0.1:7784
`,
Flag: flag.NewFlagSet("Adapter params", flag.ExitOnError),
CommonFlag: flag.NewFlagSet("Common params", flag.ExitOnError),
DebugFlag: flag.NewFlagSet("Debug params", flag.ExitOnError),
}

func init() {
Expand Down Expand Up @@ -74,13 +78,15 @@ func startAdapterServer(adapterAddr string, adapterUseMirrorAddr string) func()
}

func runAdapter(cmd *Command, args []string) {
commonFlagsInit(cmd)

if len(args) != 1 {
ConsoleLog.Error("adapter command need listen address as param")
SetExitStatus(1)
help = true
printCommandHelp(cmd)
Exit()
}

commonFlagsInit(cmd)
configInit()
bgServerInit()

Expand Down
8 changes: 7 additions & 1 deletion cmd/cql/internal/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ type Command struct {
// Long is the long message shown in the 'cql help <this-command>' output.
Long string

// DebugFlag is a set of debug flags specific to this command.
DebugFlag *flag.FlagSet

// CommonFlag is a set of common flags specific to this command.
CommonFlag *flag.FlagSet

// Flag is a set of flags specific to this command.
Flag flag.FlagSet
Flag *flag.FlagSet
}

// LongName returns the command's long name: all the words in the usage line between "cql" and a flag or argument,
Expand Down
30 changes: 13 additions & 17 deletions cmd/cql/internal/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import (
var (
configFile string
password string
noPassword bool
withPassword bool
consoleLogLevel string // foreground console log level

waitTxConfirmation bool // wait for transaction confirmation before exiting
Expand All @@ -55,26 +55,22 @@ var (
)

func addCommonFlags(cmd *Command) {
cmd.Flag.BoolVar(&help, "help", false, "Show help message")
cmd.Flag.BoolVar(&noPassword, "no-password", true,
"Use empty password for master key")
cmd.CommonFlag.BoolVar(&help, "help", false, "Show help message")
cmd.CommonFlag.BoolVar(&withPassword, "with-password", false,
"Enter the passphrase for private.key")

// debugging flags.
cmd.Flag.StringVar(&password, "password", "",
"Master key password for covenantsql (NOT SAFE, for debug or script only)")
cmd.Flag.StringVar(&consoleLogLevel, "log-level", "info",
cmd.DebugFlag.StringVar(&password, "password", "",
"Passphrase for encrypting private.key (NOT SAFE, for debug or script only)")
cmd.DebugFlag.StringVar(&consoleLogLevel, "log-level", "info",
"Console log level: trace debug info warning error fatal panic")
cmd.Flag.BoolVar(&asymmetric.BypassSignature, "bypass-signature", false,
cmd.DebugFlag.BoolVar(&asymmetric.BypassSignature, "bypass-signature", false,
"Disable signature sign and verify, for testing")
}

func commonFlagsInit(cmd *Command) {
if help {
_, _ = fmt.Fprintf(os.Stdout, "usage: %s\n", cmd.UsageLine)
_, _ = fmt.Fprintf(os.Stdout, cmd.Long)
_, _ = fmt.Fprintf(os.Stdout, "\nParams:\n")
cmd.Flag.SetOutput(os.Stdout)
cmd.Flag.PrintDefaults()
printCommandHelp(cmd)
Exit()
}

Expand All @@ -86,15 +82,15 @@ func commonFlagsInit(cmd *Command) {
}

func addConfigFlag(cmd *Command) {
cmd.Flag.StringVar(&configFile, "config", "~/.cql/config.yaml",
"Config file for covenantsql (Usually no need to set, default is enough.)")
cmd.CommonFlag.StringVar(&configFile, "config", "~/.cql/config.yaml",
"Config file for CovanantSQL (Usually no need to set, default is enough.)")
}

func configInit() {
configFile = utils.HomeDirExpand(configFile)

if password == "" {
password = readMasterKey(noPassword)
password = readMasterKey(!withPassword)
}

// init covenantsql driver
Expand Down Expand Up @@ -133,7 +129,7 @@ func wait(txHash hash.Hash) (err error) {

func addBgServerFlag(cmd *Command) {
cmd.Flag.StringVar(&tmpPath, "tmp-path", "",
"Background service temp file path, use \"dirname `mktemp -u`\" to check it out")
"Background service temp file path, use \"dirname $(mktemp -u)\" to check it out")
cmd.Flag.StringVar(&bgLogLevel, "bg-log-level", "info",
"Background service log level: trace debug info warning error fatal panic")
}
Expand Down
9 changes: 7 additions & 2 deletions cmd/cql/internal/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ If those params are set, it will run SQL script and exit without staying console
e.g.
cql console -command "create table test1(test2 int);" covenantsql://4119ef997dedc585bfbcfae00ab6b87b8486fab323a8e107ea1fd4fc4f7eba5c
`,
Flag: flag.NewFlagSet("Console params", flag.ExitOnError),
CommonFlag: flag.NewFlagSet("Common params", flag.ExitOnError),
DebugFlag: flag.NewFlagSet("Debug params", flag.ExitOnError),
}

var (
Expand Down Expand Up @@ -326,6 +329,8 @@ func run(u *user.User) (err error) {
func runConsole(cmd *Command, args []string) {
configFile = utils.HomeDirExpand(configFile)

commonFlagsInit(cmd)

var err error
// load config
if conf.GConf, err = conf.LoadConfig(configFile); err != nil {
Expand Down Expand Up @@ -375,11 +380,11 @@ func runConsole(cmd *Command, args []string) {
} else {
ConsoleLog.Error("neither local dsn storage exists nor a dsn string present")
SetExitStatus(1)
help = true
printCommandHelp(cmd)
Exit()
}
}

commonFlagsInit(cmd)
configInit()

usqlRegister()
Expand Down
Loading