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

cli: Add Config.Run to set IO streams and args #182

Closed
wants to merge 1 commit into from
Closed

cli: Add Config.Run to set IO streams and args #182

wants to merge 1 commit into from

Conversation

abhinav
Copy link

@abhinav abhinav commented Aug 21, 2022

Adds a new Config type which allows setting Stdout, Stdin, and Stderr,
and a Config.Run method that accepts the command line arguments.

The new exported APIs are,

package cli

type Config struct {
  Stdin  io.Reader
  Stdout io.Writer
  Stderr io.Writer
}

func (cfg *Config) Run(args []string) (exitCode int)

These two combined are a version of cli.Run that does not rely on
the process' global IO streams, or on os.Args.

Testing:
This updates cli_test to use Config.Run instead of setting up the cli
struct, so this exercises Config.Run for all core test cases.
This also adds tests that verify the no-op behavior of each field of
Config.

Resolves #181

Adds a new Config type which allows setting Stdout, Stdin, and Stderr,
and a Config.Run method that accepts the command line arguments.

The new exported APIs are,

    package cli

    type Config struct {
      Stdin  io.Reader
      Stdout io.Writer
      Stderr io.Writer
    }

    func (cfg *Config) Run(args []string) (exitCode int)

These two combined are a version of cli.Run that does not rely on
the process' global IO streams, or on os.Args.

Testing:
This updates cli_test to use Config.Run instead of setting up the cli
struct, so this exercises Config.Run for all core test cases.
This also adds tests that verify the no-op behavior of each field of
Config.

Resolves #181
@abhinav
Copy link
Author

abhinav commented Aug 21, 2022

This isn't safe per comment in #181.

@abhinav abhinav closed this Aug 21, 2022
@abhinav abhinav deleted the run-with-args branch August 22, 2022 02:04
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

Successfully merging this pull request may close these issues.

cli: Expose Run with args and IO streams
1 participant