<commit_before>package main

import (
	"bytes"
	"errors"
	"os"
	"os/exec"
	"path/filepath"
	"strings"

	"github.com/codegangsta/cli"
)

const (
	GOPKG = repoType(iota)
	HTTP
	HTTPS
	GIT
	SSH
)

type repoType int

var (
	getCommandDesc = `Clones a package into your GOPATH using the go tool chain, 
   creates a link between it and your workspace, and if possible updates 
   the repos remote origin to use SSH.`

	getCommand = cli.Command{
		Name:        "get",
		Usage:       "'go get' a repo, and link it to your workspace",
		Description: getCommandDesc,
		Action: func(c *cli.Context) {
			err := getCommandAction(c)
			if err != nil {
				exitStatus = FAIL
				return
			}
		},
		Flags: []cli.Flag{
			cli.BoolFlag{"update, u", "Update existing code"},
			cli.BoolFlag{"download-only, d", "Only download the code, don't install with the go toolchain (go build, go install)"},
			cli.BoolFlag{"force, f", "Force updating and linking (Irreverseible)"},
			cli.BoolFlag{"no-ssh", "Do not update the remote origin to use SSH"},
			cli.StringFlag{"ssh-user", "<user>", "Set the user for the SSH url (Default: git)"},
		},
	}

	cloneCommand = cli.Command{
		Name:  "clone",
		Usage: "Clone the repo into your GOPATH",
		Action: func(c *cli.Context) {
			err := cloneCommandAction(c)
			if err != nil {
				exitStatus = FAIL
				return
			}
		},
		Flags: []cli.Flag{
			cli.BoolFlag{"update, u", "Update existing code"},
			cli.BoolFlag{"download-only, d", "Only download the code, don't install with the go toolchain (go build, go install)"},
		},
	}

	linkCommand = cli.Command{
		Name:  "link",
		Usage: "Create a link from the GOPATH/project to WORKSPACE/project",
		Action: func(c *cli.Context) {
			err := linkCommandAction(c)
			if err != nil {
				exitStatus = FAIL
				return
			}
		},
		Flags: []cli.Flag{
			cli.BoolFlag{"update, u", "Update existing link"},
			cli.BoolFlag{"force, f", "Force updating and linking (Irreverseible)"},
		},
	}

	updateRemoteCommand = cli.Command{
		Name:  "update-remote",
		Usage: "Updates the git remote origin url to use SSH",
		Action: func(c *cli.Context) {
			err := updateRemoteCommandAction(c)
			if err != nil {
				exitStatus = FAIL
				return
			}
		},
		Flags: []cli.Flag{
			cli.StringFlag{"ssh-user", "git", "Set the user for the SSH url (Default: git)"},
		},
	}
)

func getCommandAction(c *cli.Context) error {
	err := cloneCommandAction(c)
	if err != nil {
		return err
	}
	err = linkCommandAction(c)
	if err != nil {
		return err
	}
	if !c.Bool("no-ssh") {
		err = updateRemoteCommandAction(c)
		if err != nil {
			return err
		}
	}
	return nil
}

func cloneCommandAction(c *cli.Context) error {
	pkgpath := projectFromURL(c.Args().First())
	log.Info("Getting package: %v", pkgpath)
	args := []string{"get"}
	if c.Bool("update") {
		args = append(args, "-u")
		//log.Debug(" ----> running %v", concat("go", " ", "get", " -u ", pkgpath))
		//err = pipeFromExec(os.Stdout, "go", "get", "-u", pkgpath)
	}
	if c.Bool("download-only") {
		args = append(args, "-d")
		//log.Debug(" ----> running %v", concat("go", " ", "get", " ", pkgpath))
		//err = pipeFromExec(os.Stdout, "go", "get", pkgpath)<commit_msg>Removed unnecessary comments<commit_after>package main

import (
	"bytes"
	"errors"
	"os"
	"os/exec"
	"path/filepath"
	"strings"

	"github.com/codegangsta/cli"
)

const (
	GOPKG = repoType(iota)
	HTTP
	HTTPS
	GIT
	SSH
)

type repoType int

var (
	getCommandDesc = `Clones a package into your GOPATH using the go tool chain, 
   creates a link between it and your workspace, and if possible updates 
   the repos remote origin to use SSH.`

	getCommand = cli.Command{
		Name:        "get",
		Usage:       "'go get' a repo, and link it to your workspace",
		Description: getCommandDesc,
		Action: func(c *cli.Context) {
			err := getCommandAction(c)
			if err != nil {
				exitStatus = FAIL
				return
			}
		},
		Flags: []cli.Flag{
			cli.BoolFlag{"update, u", "Update existing code"},
			cli.BoolFlag{"download-only, d", "Only download the code, don't install with the go toolchain (go build, go install)"},
			cli.BoolFlag{"force, f", "Force updating and linking (Irreverseible)"},
			cli.BoolFlag{"no-ssh", "Do not update the remote origin to use SSH"},
			cli.StringFlag{"ssh-user", "<user>", "Set the user for the SSH url (Default: git)"},
		},
	}

	cloneCommand = cli.Command{
		Name:  "clone",
		Usage: "Clone the repo into your GOPATH",
		Action: func(c *cli.Context) {
			err := cloneCommandAction(c)
			if err != nil {
				exitStatus = FAIL
				return
			}
		},
		Flags: []cli.Flag{
			cli.BoolFlag{"update, u", "Update existing code"},
			cli.BoolFlag{"download-only, d", "Only download the code, don't install with the go toolchain (go build, go install)"},
		},
	}

	linkCommand = cli.Command{
		Name:  "link",
		Usage: "Create a link from the GOPATH/project to WORKSPACE/project",
		Action: func(c *cli.Context) {
			err := linkCommandAction(c)
			if err != nil {
				exitStatus = FAIL
				return
			}
		},
		Flags: []cli.Flag{
			cli.BoolFlag{"update, u", "Update existing link"},
			cli.BoolFlag{"force, f", "Force updating and linking (Irreverseible)"},
		},
	}

	updateRemoteCommand = cli.Command{
		Name:  "update-remote",
		Usage: "Updates the git remote origin url to use SSH",
		Action: func(c *cli.Context) {
			err := updateRemoteCommandAction(c)
			if err != nil {
				exitStatus = FAIL
				return
			}
		},
		Flags: []cli.Flag{
			cli.StringFlag{"ssh-user", "git", "Set the user for the SSH url (Default: git)"},
		},
	}
)

func getCommandAction(c *cli.Context) error {
	err := cloneCommandAction(c)
	if err != nil {
		return err
	}
	err = linkCommandAction(c)
	if err != nil {
		return err
	}
	if !c.Bool("no-ssh") {
		err = updateRemoteCommandAction(c)
		if err != nil {
			return err
		}
	}
	return nil
}

func cloneCommandAction(c *cli.Context) error {
	pkgpath := projectFromURL(c.Args().First())
	log.Info("Getting package: %v", pkgpath)
	args := []string{"get"}
	if c.Bool("update") {
		args = append(args, "-u")
	}
	if c.Bool("download-only") {
		args = append(args, "-d")
{'fraction_non_alphanumeric': 0.15117045829212, 'fraction_numerical': 0.0, 'mean_word_length': 3.380505415162455, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5949580', 'n_tokens_mistral': 2387, 'n_tokens_neox': 2111, 'n_words': 631}