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

Update rubycommand #37

Merged
merged 10 commits into from
Sep 24, 2021
Merged

Update rubycommand #37

merged 10 commits into from
Sep 24, 2021

Conversation

godrei
Copy link
Contributor

@godrei godrei commented Sep 24, 2021

Checklist

Context

This PR finishes the previous go-utils package update in the command/rubycommand package and in the command/gems/bundler.go file.

The previous migration introduced a global temporaryFactory, which blocks us in the generated command.Command customization (setting command.Opts for specifying work dir for example).

An example of how to adopt these changes: bitrise-steplib/steps-fastlane#84.

To finalize this PR a related go-utils PR needs to be merged and go-utils dependency needs to be updated here.

Changes

  • Introduce ruby.CommandFactory interface and implementing commandFactory struct for creating ruby related commands.

    • CommandFactory.Create replaces the previous rubycommand.NewWithParams, rubycommand.NewFromSlice and rubycommand.New functions.
    • CreateBundleExec replaces the previous gems.BundleExecPrefix functionality.
    • CreateBundleInstall replaces the previous gems.BundleInstallCommand function.
    • CreateGemInstall replaces the previous rubycommand.GemInstall function.
    • CreateGemUpdate replaces the previous rubycommand.GemUpdate function.
  • Introduce ruby.Environment interface and implementing environment struct.

    • RubyInstallType replaces the previous rubycommand.RubyInstallType function.
    • IsGemInstalled replaces the previous rubycommand. IsGemInstalled function.
    • IsSpecifiedRbenvRubyInstalled replaces the previous rubycommand. IsSpecifiedRbenvRubyInstalled function.
  • gems.InstallBundlerCommand removed in favor of:

cmds := factory.CreateGemInstall("bunder", "1.0.0", false, true, &command.Opts{
	Stdout: os.Stdout,
	Stderr: os.Stderr,
	Dir:    workDir,
})
for _, cmd := range cmds {
	log.Donef("$ %s", cmd.PrintableCommandArgs())
	fmt.Println()

	if err := cmd.Run(); err != nil {
		failf("command failed, error: %s", err)
	}
}
  • gems.RbenvVersionsCommand removed in favor of:
if _, err := cmdLocator.LookPath("rbenv"); err != nil {
	cmd := factory.Create("rbenv", []string{"versions"}, &command.Opts{
		Stderr: os.Stderr,
		Stdout: os.Stdout,
		Dir:    workDir,
	})

	fmt.Println()
	log.Donef("$ %s", cmd.PrintableCommandArgs())
	if err := cmd.Run(); err != nil {
		log.Warnf("%s", err)
	}
}
  • create mocks for ruby.CommandFactory and ruby.Environment.

Investigation details

Decisions

ruby/command.go Outdated
return slice
}

func sudoNeeded(installType InstallType, slice ...string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would use a more descriptive arg name than slice, something like command

ofalvai
ofalvai previously approved these changes Sep 24, 2021
@godrei godrei merged commit 851d30b into master Sep 24, 2021
@godrei godrei deleted the update-rubycommand branch September 24, 2021 11:41
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.

2 participants