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
6419ff4b
Commit
6419ff4b
authored
Mar 13, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
infer arg type
parent
d3fb2095
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
15 deletions
+37
-15
src/registry/registries/command-put.ts
src/registry/registries/command-put.ts
+12
-1
src/utility/index.ts
src/utility/index.ts
+1
-0
src/utility/native-type-mapping.ts
src/utility/native-type-mapping.ts
+21
-0
src/utility/utility.ts
src/utility/utility.ts
+3
-14
No files found.
src/registry/registries/command-put.ts
View file @
6419ff4b
...
@@ -7,7 +7,11 @@ import {
...
@@ -7,7 +7,11 @@ import {
TemplateConfig
,
TemplateConfig
,
}
from
'
../../def
'
;
}
from
'
../../def
'
;
import
{
MethodRegistry
}
from
'
../abstract-registry
'
;
import
{
MethodRegistry
}
from
'
../abstract-registry
'
;
import
{
applyOptionToCommand
,
registerTemplate
}
from
'
../../utility
'
;
import
{
applyNativeTypeToArg
,
applyOptionToCommand
,
registerTemplate
,
}
from
'
../../utility
'
;
// eslint-disable-next-line @typescript-eslint/no-namespace
// eslint-disable-next-line @typescript-eslint/no-namespace
export
namespace
CommandPut
{
export
namespace
CommandPut
{
...
@@ -40,6 +44,13 @@ export namespace CommandPut {
...
@@ -40,6 +44,13 @@ export namespace CommandPut {
applyOptionToCommand
(
ctx
,
cmd
,
data
,
nativeType
),
applyOptionToCommand
(
ctx
,
cmd
,
data
,
nativeType
),
);
);
preRegistry
.
extend
(
'
arg
'
,
(
data
,
cmd
,
ctx
,
nativeType
)
=>
{
const
arg
=
cmd
.
_arguments
[
data
];
if
(
arg
)
{
applyNativeTypeToArg
(
arg
,
nativeType
);
}
});
preRegistry
.
extend
(
'
user
'
,
(
data
,
cmd
)
=>
{
preRegistry
.
extend
(
'
user
'
,
(
data
,
cmd
)
=>
{
if
(
data
)
{
if
(
data
)
{
cmd
.
userFields
(
data
);
cmd
.
userFields
(
data
);
...
...
src/utility/index.ts
View file @
6419ff4b
export
*
from
'
./utility
'
;
export
*
from
'
./utility
'
;
export
*
from
'
./native-type-mapping
'
;
src/utility/native-type-mapping.ts
0 → 100644
View file @
6419ff4b
import
{
Argv
}
from
'
koishi
'
;
// eslint-disable-next-line @typescript-eslint/ban-types
const
nativeTypeMapping
=
new
Map
<
Function
,
Argv
.
Type
>
();
nativeTypeMapping
.
set
(
String
,
'
string
'
);
nativeTypeMapping
.
set
(
Number
,
'
number
'
);
nativeTypeMapping
.
set
(
Boolean
,
'
boolean
'
);
nativeTypeMapping
.
set
(
Date
,
'
date
'
);
export
function
applyNativeTypeToArg
(
arg
:
Argv
.
Declaration
,
// eslint-disable-next-line @typescript-eslint/ban-types
nativeType
:
Function
,
)
{
if
(
arg
.
type
||
!
nativeType
)
{
return
;
}
if
(
nativeTypeMapping
.
has
(
nativeType
))
{
arg
.
type
=
nativeTypeMapping
.
get
(
nativeType
);
}
}
src/utility/utility.ts
View file @
6419ff4b
import
{
Argv
,
Command
,
Context
,
Dict
}
from
'
koishi
'
;
import
{
Command
,
Context
,
Dict
}
from
'
koishi
'
;
import
{
import
{
CommandOptionConfig
,
CommandOptionConfig
,
ContextSelector
,
ContextSelector
,
OnContextFunction
,
OnContextFunction
,
TemplateConfig
,
TemplateConfig
,
}
from
'
../def
'
;
}
from
'
../def
'
;
import
{
applyNativeTypeToArg
}
from
'
./native-type-mapping
'
;
export
function
applySelector
(
export
function
applySelector
(
ctx
:
Context
,
ctx
:
Context
,
...
@@ -55,13 +56,6 @@ export const registerTemplate = (
...
@@ -55,13 +56,6 @@ export const registerTemplate = (
}
}
};
};
// eslint-disable-next-line @typescript-eslint/ban-types
const
nativeTypeMapping
=
new
Map
<
Function
,
Argv
.
Type
>
();
nativeTypeMapping
.
set
(
String
,
'
string
'
);
nativeTypeMapping
.
set
(
Number
,
'
number
'
);
nativeTypeMapping
.
set
(
Boolean
,
'
boolean
'
);
nativeTypeMapping
.
set
(
Date
,
'
date
'
);
export
function
applyOptionToCommand
(
export
function
applyOptionToCommand
(
ctx
:
Context
,
ctx
:
Context
,
cmd
:
Command
,
cmd
:
Command
,
...
@@ -81,11 +75,6 @@ export function applyOptionToCommand(
...
@@ -81,11 +75,6 @@ export function applyOptionToCommand(
delete
clonedConfig
.
description
;
delete
clonedConfig
.
description
;
cmd
=
cmd
.
option
(
name
,
desc
,
clonedConfig
);
cmd
=
cmd
.
option
(
name
,
desc
,
clonedConfig
);
const
option
=
cmd
.
_options
[
name
];
const
option
=
cmd
.
_options
[
name
];
if
(
!
option
.
type
&&
nativeType
)
{
applyNativeTypeToArg
(
option
,
nativeType
);
const
inferredType
=
nativeTypeMapping
.
get
(
nativeType
);
if
(
inferredType
)
{
option
.
type
=
inferredType
;
}
}
return
cmd
;
return
cmd
;
}
}
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