Skip to content

Commit

Permalink
fix(commands): fix mutable option snapshot, fix koishijs#281
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Dec 30, 2023
1 parent d34abc0 commit c064ab9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions plugins/commands/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Argv, Command, Context, Dict, remove, Schema } from 'koishi'
import { Argv, clone, Command, Context, Dict, remove, Schema } from 'koishi'
import ConsoleExtension from './console'
import CommandExtension from './command'

Expand Down Expand Up @@ -112,8 +112,8 @@ export class CommandManager {
parent: command.parent,
initial: {
aliases: command._aliases,
options: command._options,
config: command.config,
options: clone(command._options),
config: clone(command.config),
},
override: {
aliases: command._aliases,
Expand Down Expand Up @@ -240,6 +240,11 @@ export class CommandManager {
if (override.config && !Object.keys(override.config).length) {
delete override.config
}
for (const key in override.options) {
if (override.options[key] && !Object.keys(override.options[key]).length) {
delete override.options[key]
}
}
if (override.options && !Object.keys(override.options).length) {
delete override.options
}
Expand Down

0 comments on commit c064ab9

Please sign in to comment.