command #16

Merged
andrey merged 2 commits from command into master 2026-01-06 16:49:23 +03:00
8 changed files with 23 additions and 28 deletions

View File

@@ -126,8 +126,7 @@ func Execute(ctx context.Context, in config.Provider, out output.Output) error {
return nil
}
const tpl = `
The <info>%[2]s</info> command displays help for a given command:
const tpl = `The <info>%[2]s</info> command displays help for a given command:
<info>%[1]s %[2]s list</info>
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>

View File

@@ -6,14 +6,12 @@ import (
"gitoa.ru/go-4devs/console/setting"
)
const tpl = `
The <info>%[2]s</info> command lists all commands:
const tpl = `The <info>%[2]s</info> command lists all commands:
<info>%[1]s %[2]s</info>
You can also display the commands for a specific namespace:
<info>%[1]s %[2]s test</info>
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) {
return fmt.Sprintf(tpl, data.Bin, data.Name), nil

View File

@@ -9,6 +9,7 @@ import (
"gitoa.ru/go-4devs/config/provider/env"
"gitoa.ru/go-4devs/config/provider/memory"
"gitoa.ru/go-4devs/console"
"gitoa.ru/go-4devs/console/command/dump"
"gitoa.ru/go-4devs/console/example/pkg/command"
)
@@ -23,12 +24,13 @@ func main() {
console.
New(console.WithInput(
chain.New(
arg.New(arg.WithArgs(os.Args)),
arg.New(arg.WithArgs(os.Args[console.ResolveSkip(0):])),
env.New(Namespace, AppName),
&memory.Default{},
),
)).
Add(
dump.Command(),
command.Long(),
command.Args(),
).

View File

@@ -4,6 +4,7 @@ import (
"context"
"gitoa.ru/go-4devs/console"
"gitoa.ru/go-4devs/console/command/dump"
"gitoa.ru/go-4devs/console/example/pkg/command"
)
@@ -11,6 +12,7 @@ func main() {
console.
New().
Add(
dump.Command(),
command.Hello(),
command.Args(),
command.Hidden(),

View File

@@ -5,6 +5,6 @@ go 1.24.0
toolchain go1.24.1
require (
gitoa.ru/go-4devs/config v0.0.8
gitoa.ru/go-4devs/console v0.2.1-0.20260105202444-e2c6fc0a35a4
gitoa.ru/go-4devs/config v0.0.10
gitoa.ru/go-4devs/console v0.4.0
)

View File

@@ -1,6 +1,4 @@
gitoa.ru/go-4devs/config v0.0.8 h1:o4p8I9jWJMfiFVVKr50IqCGj1fF+8kmSPDkH0deRvn4=
gitoa.ru/go-4devs/config v0.0.8/go.mod h1:jHKqVafFVW400LC0M4i1ifPapiI9sqpX/QTh+VMadKw=
gitoa.ru/go-4devs/console v0.2.0 h1:6lsbArs99GA8vGdnwNDThZNKjFNctNtTlSCUjhgwIpU=
gitoa.ru/go-4devs/console v0.2.0/go.mod h1:xi4Svw7T+lylckAQiJQS/2qwDwF4YbIanlhcbQrBAiI=
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=
gitoa.ru/go-4devs/config v0.0.10 h1:NSagD0voj77/IGqRGsbR0DZmDvFcxbx+oRoWQnLnSy4=
gitoa.ru/go-4devs/config v0.0.10/go.mod h1:cLW1+4E4uM4Pw+z4RuKEKbO1Lz6UTs2b2fTPyeEgTx8=
gitoa.ru/go-4devs/console v0.4.0 h1:3N4VMWsHsaP32nWHxALxjPhp/MhYx1hXZdDl3xGJQ3k=
gitoa.ru/go-4devs/console v0.4.0/go.mod h1:+J69iA4KQfC2H1FxItwL4pLkb3oW8g466qUSo0jWYjo=

View File

@@ -5,12 +5,12 @@ import (
"gitoa.ru/go-4devs/config"
"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"
"gitoa.ru/go-4devs/console"
"gitoa.ru/go-4devs/console/command"
"gitoa.ru/go-4devs/console/output"
"gitoa.ru/go-4devs/console/param"
"gitoa.ru/go-4devs/console/setting"
)
func CreateUser(required bool) command.Command {
@@ -19,7 +19,7 @@ func CreateUser(required bool) command.Command {
"Creates a new user.",
UserExecute,
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
}),
)
@@ -27,7 +27,7 @@ func CreateUser(required bool) command.Command {
func UserConfigure(required bool) 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 {
opts = append(opts, option.Required)
}

View File

@@ -29,7 +29,8 @@ var (
"commands": txtCommands,
}
txtHelpTemplate = template.Must(template.New("txt_template").
txtHelpTemplate = template.Must(
template.New("txt_template").
Funcs(txtFunc).
Parse(`
{{- if .Description -}}
@@ -38,8 +39,8 @@ var (
{{ end -}}
{{- usage . }}
{{- definition .Options }}
{{- help . }}
`))
{{- help . }}`),
)
txtListTemplate = template.Must(template.New("txt_list").
Funcs(txtFunc).
@@ -149,12 +150,7 @@ func txtHelp(cmd Command) string {
return ""
}
var buf bytes.Buffer
buf.WriteString("\n<comment>Help:</comment>")
buf.WriteString(cmd.Help)
return buf.String()
return "\n<comment>Help:</comment>\n" + cmd.Help + "\n"
}
func txtDefinition(options config.Options) string {