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

Document Halt #961

Open
1 task done
lishaduck opened this issue Dec 4, 2024 · 2 comments
Open
1 task done

Document Halt #961

lishaduck opened this issue Dec 4, 2024 · 2 comments

Comments

@lishaduck
Copy link

lishaduck commented Dec 4, 2024

EDIT: Halt should get documented so people can know how it exists.

Old description below:


Hello! I'm trying to convert some existing code that uses child_process to zx. It's working fine, but I want to print out the commands that are run. I know I can enable verbose mode and override the logger, but that isn't as flexible as the logging I need to do. I see zx 8 uses zurk under the hood, which has a buildCmd function. While that could work, it's not a template tag, so I'd need to manually verify it's actually what zx is running. I'd love an API to create commands without running them (as I think about it, it'd also be useful if xz exposed an exec function to run a command from the proposed builder tag).

  • I'd be willing to PR this if this is a direction you're willing to consider.
@antongolub
Copy link
Collaborator

antongolub commented Dec 5, 2024

I'd love an API to create commands without running

You can do it right now:

const p = $({halt: true})`cdm --foo=${foo}`
console.log(f.cmd)
const o = await p.run()

You can inject verification layer in various ways:

  1. Build a wrapper
const _$ = (pieces: TemplateStringsArray | Partial<Options>, ...args: any) => {
   if (isTemplateString(pieces, args)) {
      const p = $({halt: true}).apply(...)
      console.log(f.cmd)
      const o = await p.run()
    }
    return ...

}
  1. Override ProcessPromise proto
const _run = ProcessPromise.prototype.run
ProcessPromise.prototype.run = function () {
  // ... custom check
  return _run.call(this)
}
  1. Mix custom logger
const _log = $.log
const _$ = $({log: (entry) => {
  if (entry.kind === 'cmd') {
     // ... check
  }
  return _log(entry)
}})

@lishaduck
Copy link
Author

lishaduck commented Dec 5, 2024

const p = $({halt: true})`cdm --foo=${foo}`
console.log(f.cmd)
const o = await p.run()

Yeah, that looks like what I want! I'd seen halt in intellisense but it isn't documented, so I didn't know what it did.

@lishaduck lishaduck changed the title Expose a builder tag Document Halt Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants