Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware order of operations #11

Closed
coreybutler opened this issue Mar 30, 2022 · 0 comments
Closed

Middleware order of operations #11

coreybutler opened this issue Mar 30, 2022 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@coreybutler
Copy link
Member

Issue:
Middleware assigned to the shell is executing after middleware assigned to specific commands.

How To Reproduce:

let status = []
const cmd = new Command({
  name: 'run',
  async handler(meta) {
    return meta.input
  }
})

cmd.use(async function(meta, next) {
  status.push('2')
  next()
})

const sh = new Shell({
  name: 'test',
  use: [
    (meta, next) => {
      status.push('1')
      next()
    }
  ],
  commands: [cmd]
})

sh.exec(['run', 'other'])

Expected Behavior:
The value of status should be 1,2, but is actually 2,1.

Middleware should be executed according to the hierarchy of the command, i.e.:

graph LR
sh[1. shell middleware]
c[2. command middleware]
s[3. subcommand middleware]

sh-->c
c-->s
Loading

It currently runs in the opposite order.

@coreybutler coreybutler added the bug Something isn't working label Mar 30, 2022
@coreybutler coreybutler self-assigned this Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant