command #16
@@ -126,8 +126,7 @@ func Execute(ctx context.Context, in config.Provider, out output.Output) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const tpl = `
|
const tpl = `The <info>%[2]s</info> command displays help for a given command:
|
||||||
The <info>%[2]s</info> command displays help for a given command:
|
|
||||||
<info>%[1]s %[2]s list</info>
|
<info>%[1]s %[2]s list</info>
|
||||||
You can also output the help in other formats by using the <comment>--format</comment> option:
|
You can also output the help in other formats by using the <comment>--format</comment> option:
|
||||||
<info>%[1]s %[2]s --format=xml list</info>
|
<info>%[1]s %[2]s --format=xml list</info>
|
||||||
|
|||||||
@@ -6,14 +6,12 @@ import (
|
|||||||
"gitoa.ru/go-4devs/console/setting"
|
"gitoa.ru/go-4devs/console/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const tpl = `
|
const tpl = `The <info>%[2]s</info> command lists all commands:
|
||||||
The <info>%[2]s</info> command lists all commands:
|
|
||||||
<info>%[1]s %[2]s</info>
|
<info>%[1]s %[2]s</info>
|
||||||
You can also display the commands for a specific namespace:
|
You can also display the commands for a specific namespace:
|
||||||
<info>%[1]s %[2]s test</info>
|
<info>%[1]s %[2]s test</info>
|
||||||
You can also output the information in other formats by using the <comment>--format</comment> option:
|
You can also output the information in other formats by using the <comment>--format</comment> option:
|
||||||
<info>%[1]s %[2]s --format=xml</info>
|
<info>%[1]s %[2]s --format=xml</info>`
|
||||||
`
|
|
||||||
|
|
||||||
func Help(data setting.HData) (string, error) {
|
func Help(data setting.HData) (string, error) {
|
||||||
return fmt.Sprintf(tpl, data.Bin, data.Name), nil
|
return fmt.Sprintf(tpl, data.Bin, data.Name), nil
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"gitoa.ru/go-4devs/config/provider/env"
|
"gitoa.ru/go-4devs/config/provider/env"
|
||||||
"gitoa.ru/go-4devs/config/provider/memory"
|
"gitoa.ru/go-4devs/config/provider/memory"
|
||||||
"gitoa.ru/go-4devs/console"
|
"gitoa.ru/go-4devs/console"
|
||||||
|
"gitoa.ru/go-4devs/console/command/dump"
|
||||||
"gitoa.ru/go-4devs/console/example/pkg/command"
|
"gitoa.ru/go-4devs/console/example/pkg/command"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,12 +24,13 @@ func main() {
|
|||||||
console.
|
console.
|
||||||
New(console.WithInput(
|
New(console.WithInput(
|
||||||
chain.New(
|
chain.New(
|
||||||
arg.New(arg.WithArgs(os.Args)),
|
arg.New(arg.WithArgs(os.Args[console.ResolveSkip(0):])),
|
||||||
env.New(Namespace, AppName),
|
env.New(Namespace, AppName),
|
||||||
&memory.Default{},
|
&memory.Default{},
|
||||||
),
|
),
|
||||||
)).
|
)).
|
||||||
Add(
|
Add(
|
||||||
|
dump.Command(),
|
||||||
command.Long(),
|
command.Long(),
|
||||||
command.Args(),
|
command.Args(),
|
||||||
).
|
).
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"gitoa.ru/go-4devs/console"
|
"gitoa.ru/go-4devs/console"
|
||||||
|
"gitoa.ru/go-4devs/console/command/dump"
|
||||||
"gitoa.ru/go-4devs/console/example/pkg/command"
|
"gitoa.ru/go-4devs/console/example/pkg/command"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ func main() {
|
|||||||
console.
|
console.
|
||||||
New().
|
New().
|
||||||
Add(
|
Add(
|
||||||
|
dump.Command(),
|
||||||
command.Hello(),
|
command.Hello(),
|
||||||
command.Args(),
|
command.Args(),
|
||||||
command.Hidden(),
|
command.Hidden(),
|
||||||
|
|||||||
@@ -5,6 +5,6 @@ go 1.24.0
|
|||||||
toolchain go1.24.1
|
toolchain go1.24.1
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitoa.ru/go-4devs/config v0.0.8
|
gitoa.ru/go-4devs/config v0.0.10
|
||||||
gitoa.ru/go-4devs/console v0.2.1-0.20260105202444-e2c6fc0a35a4
|
gitoa.ru/go-4devs/console v0.4.0
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
gitoa.ru/go-4devs/config v0.0.8 h1:o4p8I9jWJMfiFVVKr50IqCGj1fF+8kmSPDkH0deRvn4=
|
gitoa.ru/go-4devs/config v0.0.10 h1:NSagD0voj77/IGqRGsbR0DZmDvFcxbx+oRoWQnLnSy4=
|
||||||
gitoa.ru/go-4devs/config v0.0.8/go.mod h1:jHKqVafFVW400LC0M4i1ifPapiI9sqpX/QTh+VMadKw=
|
gitoa.ru/go-4devs/config v0.0.10/go.mod h1:cLW1+4E4uM4Pw+z4RuKEKbO1Lz6UTs2b2fTPyeEgTx8=
|
||||||
gitoa.ru/go-4devs/console v0.2.0 h1:6lsbArs99GA8vGdnwNDThZNKjFNctNtTlSCUjhgwIpU=
|
gitoa.ru/go-4devs/console v0.4.0 h1:3N4VMWsHsaP32nWHxALxjPhp/MhYx1hXZdDl3xGJQ3k=
|
||||||
gitoa.ru/go-4devs/console v0.2.0/go.mod h1:xi4Svw7T+lylckAQiJQS/2qwDwF4YbIanlhcbQrBAiI=
|
gitoa.ru/go-4devs/console v0.4.0/go.mod h1:+J69iA4KQfC2H1FxItwL4pLkb3oW8g466qUSo0jWYjo=
|
||||||
gitoa.ru/go-4devs/console v0.2.1-0.20260105202444-e2c6fc0a35a4 h1:zOk/59IvgUfCDL6ub6WX4hsqDK79FsZR0gf7s7t3fXM=
|
|
||||||
gitoa.ru/go-4devs/console v0.2.1-0.20260105202444-e2c6fc0a35a4/go.mod h1:PG/Zyj1dLh7eFlj9bgnV58+Ys6I/MTrS0q9W7oD7z4U=
|
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ import (
|
|||||||
|
|
||||||
"gitoa.ru/go-4devs/config"
|
"gitoa.ru/go-4devs/config"
|
||||||
"gitoa.ru/go-4devs/config/definition/option"
|
"gitoa.ru/go-4devs/config/definition/option"
|
||||||
cparam "gitoa.ru/go-4devs/config/param"
|
"gitoa.ru/go-4devs/config/param"
|
||||||
argument "gitoa.ru/go-4devs/config/provider/arg"
|
argument "gitoa.ru/go-4devs/config/provider/arg"
|
||||||
"gitoa.ru/go-4devs/console"
|
"gitoa.ru/go-4devs/console"
|
||||||
"gitoa.ru/go-4devs/console/command"
|
"gitoa.ru/go-4devs/console/command"
|
||||||
"gitoa.ru/go-4devs/console/output"
|
"gitoa.ru/go-4devs/console/output"
|
||||||
"gitoa.ru/go-4devs/console/param"
|
"gitoa.ru/go-4devs/console/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateUser(required bool) command.Command {
|
func CreateUser(required bool) command.Command {
|
||||||
@@ -19,7 +19,7 @@ func CreateUser(required bool) command.Command {
|
|||||||
"Creates a new user.",
|
"Creates a new user.",
|
||||||
UserExecute,
|
UserExecute,
|
||||||
command.Configure(UserConfigure(required)),
|
command.Configure(UserConfigure(required)),
|
||||||
command.Help(func(param.HData) (string, error) {
|
command.Help(func(setting.HData) (string, error) {
|
||||||
return "This command allows you to create a user...", nil
|
return "This command allows you to create a user...", nil
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@@ -27,7 +27,7 @@ func CreateUser(required bool) command.Command {
|
|||||||
|
|
||||||
func UserConfigure(required bool) func(_ context.Context, cfg config.Definition) error {
|
func UserConfigure(required bool) func(_ context.Context, cfg config.Definition) error {
|
||||||
return func(_ context.Context, cfg config.Definition) error {
|
return func(_ context.Context, cfg config.Definition) error {
|
||||||
var opts []cparam.Option
|
var opts []param.Option
|
||||||
if required {
|
if required {
|
||||||
opts = append(opts, option.Required)
|
opts = append(opts, option.Required)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ var (
|
|||||||
"commands": txtCommands,
|
"commands": txtCommands,
|
||||||
}
|
}
|
||||||
|
|
||||||
txtHelpTemplate = template.Must(template.New("txt_template").
|
txtHelpTemplate = template.Must(
|
||||||
|
template.New("txt_template").
|
||||||
Funcs(txtFunc).
|
Funcs(txtFunc).
|
||||||
Parse(`
|
Parse(`
|
||||||
{{- if .Description -}}
|
{{- if .Description -}}
|
||||||
@@ -38,8 +39,8 @@ var (
|
|||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{- usage . }}
|
{{- usage . }}
|
||||||
{{- definition .Options }}
|
{{- definition .Options }}
|
||||||
{{- help . }}
|
{{- help . }}`),
|
||||||
`))
|
)
|
||||||
|
|
||||||
txtListTemplate = template.Must(template.New("txt_list").
|
txtListTemplate = template.Must(template.New("txt_list").
|
||||||
Funcs(txtFunc).
|
Funcs(txtFunc).
|
||||||
@@ -149,12 +150,7 @@ func txtHelp(cmd Command) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
var buf bytes.Buffer
|
return "\n<comment>Help:</comment>\n" + cmd.Help + "\n"
|
||||||
|
|
||||||
buf.WriteString("\n<comment>Help:</comment>")
|
|
||||||
buf.WriteString(cmd.Help)
|
|
||||||
|
|
||||||
return buf.String()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func txtDefinition(options config.Options) string {
|
func txtDefinition(options config.Options) string {
|
||||||
|
|||||||
Reference in New Issue
Block a user