Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

simple utils to use golang os/exec

License

NotificationsYou must be signed in to change notification settings

yyle88/osexec

Repository files navigation

GitHub Workflow Status (branch)GoDocCoverage StatusSupported Go VersionsGitHub ReleaseGo Report Card

osexec

Simple utilities to use Golang'sos/exec package.

CHINESE README

中文说明

Features

  • Custom Execution Configurations: Execute commands with customizable environment variables, working paths, and shell options.

Installation

go get github.com/yyle88/osexec

CommandConfig Structure and Methods

CommandConfig structure provides a flexible way to configure and execute commands. You can set custom environment variables, directories, shell types, and debug options using a chainable interface.

NewCommandConfig() *CommandConfig

Creates and returns a newCommandConfig instance.

Example:

config:=osexec.NewCommandConfig()

Chainable Methods

  • *WithEnvs(envs []string)CommandConfig: Sets custom environment variables.
  • *WithPath(path string)CommandConfig: Sets the working path.
  • *WithShellType(shellType string)CommandConfig: Sets the shell type (e.g.,bash).
  • *WithShellFlag(shellFlag string)CommandConfig: Sets the shell flag (e.g.,-c).
  • *WithShell(shellType, shellFlag string)CommandConfig: Sets shell type and flag.
  • *WithBash()CommandConfig: Configures the command to usebash -c.
  • *WithZsh()CommandConfig: Configures the command to usezsh -c.
  • *WithSh()CommandConfig: Configures the command to usesh -c.
  • *WithDebugMode(debugMode bool)CommandConfig: Enables / disables debug mode.

Example:

package mainimport ("fmt""github.com/yyle88/osexec")funcmain() {// Create a new CommandConfig instance and set the working directory and debug modeconfig:=osexec.NewCommandConfig().WithPath("/path/to/directoryName").WithDebugMode(true)output,err:=config.Exec("echo","Hello, World!")iferr!=nil {fmt.Println("Reason:",err)}else {fmt.Println("Output:",string(output))}}

License

MIT License. SeeLICENSE.


Contributing

Contributions are welcome! To contribute:

  1. Fork the repo on GitHub (using the webpage interface).
  2. Clone the forked project (git clone https://github.com/yourname/repo-name.git).
  3. Navigate to the cloned project (cd repo-name)
  4. Create a feature branch (git checkout -b feature/xxx).
  5. Stage changes (git add .)
  6. Commit changes (git commit -m "Add feature xxx").
  7. Push to the branch (git push origin feature/xxx).
  8. Open a pull request on GitHub (on the GitHub webpage).

Please ensure tests pass and include relevant documentation updates.


Support

Welcome to contribute to this project by submitting pull requests and reporting issues.

If you find this package valuable, give me some stars on GitHub! Thank you!!!

Thank you for your support!

Happy Coding with this package! 🎉

Give me stars. Thank you!!!


GitHub Stars

starring

About

simple utils to use golang os/exec

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp