-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(devops-1938): add joy setup command (#33)
Co-authored-by: Mathieu Frenette <silphid@users.noreply.github.com>
- Loading branch information
Showing
11 changed files
with
395 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/nestoca/joy/internal/setup" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewSetupCmd() *cobra.Command { | ||
var catalogRepo string | ||
cmd := &cobra.Command{ | ||
Use: "setup", | ||
Short: "Setup joy for first time use", | ||
Long: `Setup joy for first time use. | ||
It prompts user for catalog directory, optionally cloning it if needed, creates config file and checks for required and optional dependencies.`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return setup.Setup(configDir, catalogDir, catalogRepo) | ||
}, | ||
} | ||
cmd.Flags().StringVar(&catalogRepo, "catalog-repo", "", "URL of catalog git repo (defaults to prompting user)") | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package dependencies | ||
|
||
import ( | ||
"fmt" | ||
"github.com/nestoca/joy/internal/style" | ||
"os" | ||
"os/exec" | ||
) | ||
|
||
type Dependency struct { | ||
// Command that should be found in PATH | ||
Command string | ||
|
||
// Url to dependency's website | ||
Url string | ||
|
||
// IsRequired indicates whether this is a core dependency required to run joy | ||
IsRequired bool | ||
|
||
// RequiredBy lists which joy sub-commands require this dependency | ||
RequiredBy []string | ||
} | ||
|
||
func (d *Dependency) IsInstalled() bool { | ||
cmd := exec.Command("command", "-v", d.Command) | ||
return cmd.Run() == nil | ||
} | ||
|
||
func (d *Dependency) MustBeInstalled() { | ||
if !d.IsInstalled() { | ||
fmt.Printf("😅 Oops! This command requires %s dependency (see: %s)\n", style.Code(d.Command), style.Link(d.Url)) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
var AllRequired []*Dependency | ||
var AllOptional []*Dependency | ||
|
||
func Add(dep *Dependency) { | ||
if dep.IsRequired { | ||
AllRequired = append(AllRequired, dep) | ||
} else { | ||
AllOptional = append(AllOptional, dep) | ||
} | ||
} | ||
|
||
func AllRequiredMustBeInstalled() { | ||
missingRequired := false | ||
for _, dep := range AllRequired { | ||
if dep.IsRequired && !dep.IsInstalled() { | ||
fmt.Printf("❌ The %s required dependency is missing (see %s).\n", style.Code(dep.Command), style.Link(dep.Url)) | ||
missingRequired = true | ||
} | ||
} | ||
if missingRequired { | ||
fmt.Println("😅 Oops! Joy requires those dependencies to operate. Please install them and try again! 🙏") | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.