Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
koishi-decorators
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vlssu
koishi-decorators
Commits
ec4ea5af
Commit
ec4ea5af
authored
Mar 10, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add missing things in PutOption
parent
62b42e1f
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
18 deletions
+36
-18
src/decorators/decorators.ts
src/decorators/decorators.ts
+9
-13
src/def/interfaces.ts
src/def/interfaces.ts
+1
-1
src/registry/registries/command-put.ts
src/registry/registries/command-put.ts
+3
-3
src/utility/utility.ts
src/utility/utility.ts
+23
-1
No files found.
src/decorators/decorators.ts
View file @
ec4ea5af
...
...
@@ -23,7 +23,11 @@ import {
}
from
'
koishi
'
;
import
{
Metadata
}
from
'
../meta/metadata.decorators
'
;
import
{
CommandPut
,
DoRegister
}
from
'
../registry
'
;
import
{
adaptLocaleDict
,
registerTemplate
}
from
'
../utility
'
;
import
{
adaptLocaleDict
,
applyOptionToCommand
,
registerTemplate
,
}
from
'
../utility
'
;
// Register method
...
...
@@ -139,17 +143,9 @@ export const CommandOption = (
desc
:
string
,
config
:
CommandOptionConfigWithDescription
=
{},
)
=>
CommandDef
((
cmd
,
ctx
)
=>
{
if
(
config
.
description
)
{
const
desc
=
adaptLocaleDict
(
config
.
description
);
for
(
const
[
locale
,
text
]
of
Object
.
entries
(
desc
))
{
ctx
.
i18n
.
define
(
locale
,
`commands.
${
cmd
.
name
}
.options.
${
name
}
`
,
text
);
}
}
const
clonedConfig
=
{
...
config
};
delete
clonedConfig
.
description
;
return
cmd
.
option
(
name
,
desc
,
clonedConfig
);
});
CommandDef
((
cmd
,
ctx
)
=>
applyOptionToCommand
(
ctx
,
cmd
,
{
name
,
desc
,
config
}),
);
export
const
CommandUserFields
=
(
fields
:
FieldCollector
<
'
user
'
>
)
=>
CommandDef
((
cmd
)
=>
cmd
.
userFields
(
fields
));
...
...
@@ -180,7 +176,7 @@ export const PutArgs = () => CommandPut.decorate('args');
export
const
PutOption
=
(
name
:
string
,
desc
:
string
,
config
:
Argv
.
OptionConfig
=
{},
config
:
CommandOptionConfigWithDescription
=
{},
)
=>
CommandPut
.
decorate
(
'
option
'
,
{
name
,
desc
,
config
});
export
const
PutUser
=
(
field
:
FieldCollector
<
'
user
'
>
)
=>
...
...
src/def/interfaces.ts
View file @
ec4ea5af
...
...
@@ -111,7 +111,7 @@ export interface CommandConfigExtended extends Command.Config {
export
interface
CommandOptionConfig
{
name
:
string
;
desc
:
string
;
config
?:
Argv
.
OptionConfig
;
config
?:
CommandOptionConfigWithDescription
;
}
export
type
CommandDefinitionFun
=
(
cmd
:
Command
,
ctx
:
Context
)
=>
Command
;
...
...
src/registry/registries/command-put.ts
View file @
ec4ea5af
...
...
@@ -7,7 +7,7 @@ import {
TemplateConfig
,
}
from
'
../../def
'
;
import
{
MethodRegistry
}
from
'
../abstract-registry
'
;
import
{
registerTemplate
}
from
'
../../utility
'
;
import
{
applyOptionToCommand
,
registerTemplate
}
from
'
../../utility
'
;
// eslint-disable-next-line @typescript-eslint/no-namespace
export
namespace
CommandPut
{
...
...
@@ -35,8 +35,8 @@ export namespace CommandPut {
[
Command
,
Context
]
>
();
preRegistry
.
extend
(
'
option
'
,
(
data
,
cmd
)
=>
cmd
.
option
(
data
.
name
,
data
.
desc
,
data
.
config
),
preRegistry
.
extend
(
'
option
'
,
(
data
,
cmd
,
ctx
)
=>
applyOptionToCommand
(
ctx
,
cmd
,
data
),
);
preRegistry
.
extend
(
'
user
'
,
(
data
,
cmd
)
=>
{
...
...
src/utility/utility.ts
View file @
ec4ea5af
import
{
Command
,
Context
,
Dict
}
from
'
koishi
'
;
import
{
ContextSelector
,
OnContextFunction
,
TemplateConfig
}
from
'
../def
'
;
import
{
CommandOptionConfig
,
ContextSelector
,
OnContextFunction
,
TemplateConfig
,
}
from
'
../def
'
;
export
function
applySelector
(
ctx
:
Context
,
...
...
@@ -49,3 +54,20 @@ export const registerTemplate = (
ctx
.
i18n
.
define
(
locale
,
key
,
text
);
}
};
export
function
applyOptionToCommand
(
ctx
:
Context
,
cmd
:
Command
,
def
:
CommandOptionConfig
,
)
{
const
{
name
,
desc
,
config
}
=
def
;
if
(
config
?.
description
)
{
const
desc
=
adaptLocaleDict
(
config
.
description
);
for
(
const
[
locale
,
text
]
of
Object
.
entries
(
desc
))
{
ctx
.
i18n
.
define
(
locale
,
`commands.
${
cmd
.
name
}
.options.
${
name
}
`
,
text
);
}
}
const
clonedConfig
=
{
...(
config
||
{})
};
delete
clonedConfig
.
description
;
return
cmd
.
option
(
name
,
desc
,
clonedConfig
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment