Code Monkey home page Code Monkey logo

Comments (9)

daniel-nichter avatar daniel-nichter commented on July 16, 2024 2

Renamed to BeforeExec and released as v1.4.0.

from cmd.

cgx027 avatar cgx027 commented on July 16, 2024 1

It's a good idea to me. I do want to setup the cmd.SysProcAttr.Credential so that I can run commands under another user.

cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uid, Gid: gid}

Refer to https://stackoverflow.com/a/21706757/14833782

from cmd.

daniel-nichter avatar daniel-nichter commented on July 16, 2024 1

@wenerme @Callisto13 et al. I merged PR #54 but reworked in PR #75. Here's why...

Cmd.Options is too close to the Options struct. And this latter is where I'm trying to move options so that Cmd doesn't become overloaded with optional fields. So Options.SetCmd is the better design, but it means you need to specify the callbacks like the test:

	p := cmd.NewCmdOptions(
		cmd.Options{
			SetCmd: []func(cmd *exec.Cmd){
				func(cmd *exec.Cmd) { handled = true },
			},
		},
		"/bin/ls",
	)

If that doesn't work, then I could add Cmd.SetCmd, too, which combines with any Options.SetCmd. Reason being: looking ahead, I'm thinking that v2 of this pkg move all things to Options, so Cmd.SetCmd would be a deprecated featured for the start.

from cmd.

wenerme avatar wenerme commented on July 16, 2024

currently using this fork #54

from cmd.

daniel-nichter avatar daniel-nichter commented on July 16, 2024

Re #54: do you just wanted to set SysProcAttr, or do you want a more general-purpose callback like feature (like in that PR)?

from cmd.

wenerme avatar wenerme commented on July 16, 2024

I prefer the general-purpose callback, like use this if you know what you are doing.

from cmd.

cgx027 avatar cgx027 commented on July 16, 2024

Thanks @daniel-nichter for looking into this. For my user case, both will work fine. I would vote for the general-purpose callback although(as in #54 ) as it will give people a lot more flexibility on using this cool tool.

from cmd.

wenerme avatar wenerme commented on July 16, 2024

lgtm, but SetCmd feels strange, more like BeforeExec or something, like hook

from cmd.

daniel-nichter avatar daniel-nichter commented on July 16, 2024

Yeah, the same occurred to me and I wrote it as BeforeExec at one point. Although its original intent was to set/modify the underlying os/exec.Exec, its actual function is a generic before-exec callback/hook. Will think on it, and see if others have ideas, before the v1.4 release (where this will appear officially).

from cmd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.