Skip to content

Commit

Permalink
Refactor bundle install
Browse files Browse the repository at this point in the history
  • Loading branch information
remear committed Jun 18, 2024
1 parent 2c724b2 commit fa0e9e8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 27 deletions.
10 changes: 8 additions & 2 deletions bedrock/bundler/bundler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type Options struct {
OverwriteFiles bool
SkipFiles bool
BedrockDir string
PackageManager string
BundlePath string
}

Expand Down Expand Up @@ -43,7 +42,14 @@ func Bundle(options Options) bool {
break
}

extension.Prepare(options)
prepareErr := extension.Prepare(options)

if prepareErr != nil {
fmt.Println(helpers.ErrorStyle.MarginLeft(2).Render("Failed with:"))
fmt.Println(helpers.ErrorStyle.MarginLeft(4).Render(prepareErr.Error()))

break
}

setupSucceeded := extension.Setup(options)

Expand Down
24 changes: 13 additions & 11 deletions bedrock/bundler/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,14 @@ func (e *Extension) hydrate() {
}

func (e *Extension) getSource() error {
var err error

switch {
case e.Path != "":
return nil
case e.Git != "":
err = e.getSourceFromGit()
//case e.Archive != "":
//e.getSourceFromArchive()
return e.getSourceFromGit()
}

return err
return nil
}

func (e *Extension) getSourceFromGit() error {
Expand All @@ -186,7 +182,11 @@ func (e *Extension) getSourceFromGit() error {
}

// TODO: maybe pass in the output pipe and live write the command output
_, err := helpers.ExecuteCommandInShell(exec.Command, "zsh", command)
output, err := helpers.ExecuteCommandInShell(exec.Command, "zsh", command)

if err != nil {
return errors.New(output)
}

return err
}
Expand Down Expand Up @@ -232,22 +232,24 @@ func syncFiles(step InstallStep, sourcePath string, options Options) bool {
fmt.Printf(
"%s%s",
lipgloss.NewStyle().MarginLeft(2).Render(fmt.Sprintf("%s exists.", destination)),
lipgloss.NewStyle().Foreground(helpers.COLORWARN).Bold(true).Render(fmt.Sprintf(" Attempt to overwrite? y/n/(S)kip all/(O)verwrite all) ")))
lipgloss.NewStyle().Foreground(helpers.COLORWARN).Bold(true).Render(
fmt.Sprintf(" Overwrite? y, n (default), (s)kip all, (O)verwrite all ")),
)

reader := bufio.NewReader(os.Stdin)
response, _ := reader.ReadString('\n')
response = strings.TrimSpace(response)

if response == "n" {
if response == "n" || response == "" {
fmt.Println(lipgloss.NewStyle().Bold(true).MarginLeft(2).Foreground(helpers.COLORWARN).Render("Skipping " + f.Source))
continue
} else if response == "S" {
} else if response == "s" {
skipAll = true
fmt.Println(lipgloss.NewStyle().Bold(true).MarginLeft(2).Foreground(helpers.COLORWARN).Render("Skipping remaining files"))
continue
} else if response == "O" {
overwriteAll = true
fmt.Println(lipgloss.NewStyle().Bold(true).MarginLeft(2).Foreground(helpers.COLORWARN).Render("Overwriting all files"))
fmt.Println(lipgloss.NewStyle().Bold(true).MarginLeft(2).Foreground(helpers.COLORWARN).Render("Overwriting all extension files"))
}
}

Expand Down
8 changes: 1 addition & 7 deletions cmd/bundle_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,13 @@ var installCmd = &cobra.Command{
Short: "Install the Bedrock extension bundle",
Long: "Install the Bedrock extensions defined in the bundle file",
Run: func(cmd *cobra.Command, args []string) {
//packageManager := viper.GetString("settings.package_manager")
//if len(packageManager) == 0 {
// packageManager = helpers.DefaultPkgManager()
//}

if OverwriteFiles && SkipFiles {
fmt.Println("WARN: overwrite-files and skip-files were set. Falling back to skip-files.")
OverwriteFiles = false
}

bundlerOptions := bundler.Options{
BedrockDir: helpers.BedrockDir,
//PackageManager: packageManager,
BedrockDir: helpers.BedrockDir,
OverwriteFiles: OverwriteFiles,
SkipFiles: SkipFiles,
}
Expand Down
7 changes: 0 additions & 7 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@ import (
"github.com/spf13/viper"
)

var packageManager string

var configCmd = &cobra.Command{
Use: "config",
Short: "Manage the Bedrock configuration",
Run: func(cmd *cobra.Command, args []string) {
// viper.WriteConfigAs(filepath.Join(helpers.Home, ".bedrock.json"))
},
}

func init() {
rootCmd.AddCommand(configCmd)

configCmd.Flags().StringVarP(&packageManager, "package-manager", "", helpers.DefaultPkgManager(), "Set desired package manager")
configCmd.Flags().StringVarP(&helpers.BedrockDir, "bedrock-dir", "", filepath.Join(helpers.Home, ".bedrock"), "Set the Bedrock base directory. (absolute path)")
viper.BindPFlag("settings.package_manager", configCmd.LocalFlags().Lookup("package-manager"))
viper.BindPFlag("settings.bedrock_dir", configCmd.LocalFlags().Lookup("bedrock-dir"))
}

0 comments on commit fa0e9e8

Please sign in to comment.