computersetup

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use: "computer-setup",
	Aliases: []string{
		"computersetup",
		"cs",
		"setup",
	},
	Short: "Configure host to developer preferences (cross platform)",
	Run: func(cmd *cobra.Command, args []string) {
		usrHomeDir, err := homedir.Dir()
		if err != nil {
			log.Fatal("Error getting user home directory")
		}

		err = computerSetup.DirectoryForSourceCode(usrHomeDir)
		if err != nil {
			log.Fatal("Error creating src directory")
		}
		log.Println("$HOME/src is available")

		err = computerSetup.DirectoryForUserBin(usrHomeDir)
		if err != nil {
			log.Fatal("Error creating src directory")
		}
		log.Println("$HOME/bin is available")

		tokenProvider := externalapi.GithubAuthTokenProvider{}
		githubClientProvider := externalapi.GithubClientProvider{}
		dotfiles, err := externalapi.GetMyDotfiles(&tokenProvider, &githubClientProvider)
		if err != nil {
			log.Fatalf("Error getting dotfiles %v", err)
		}

		token, err := tokenProvider.GetAuthToken()
		if err != nil {
			log.Fatalf("Error getting github auth token %v", err)
		}
		ghClient, err := githubClientProvider.GetGithubClient(token)
		if err != nil {
			log.Fatalf("Error getting github client %v", err)
		}
		user, _, err := ghClient.Users.Get(context.TODO(), "")
		if err != nil {
			log.Fatalf("Error getting github user %v", err)
		}

		gitProvider := externalcmd.GitClientProvider{}
		auth := &http.BasicAuth{
			Username: *user.Login,
			Password: token,
		}
		for _, repo := range dotfiles {
			_, innerErr := externalcmd.CloneGithubRepo(path.Join(usrHomeDir, "src"), &gitProvider, &repo, auth)
			if innerErr != nil {
				log.Fatalf("Error cloning repo %v", innerErr)
			}
		}
	},
}

RootCmd defines the root of computer setup

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL