Skip to content

Commit

Permalink
Don't use github username
Browse files Browse the repository at this point in the history
The username was never used for anything important. This also deletes
the whoami command.
  • Loading branch information
kytrinyx committed Aug 24, 2014
1 parent 34d9150 commit 07cc334
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 42 deletions.
2 changes: 0 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const (
// This defines both the auth for talking to the API, as well as
// where to put problems that get downloaded.
type Config struct {
GithubUsername string `json:"githubUsername"`
APIKey string `json:"apiKey"`
ExercismDirectory string `json:"exercismDirectory"`
Hostname string `json:"hostname"`
Expand Down Expand Up @@ -203,7 +202,6 @@ func demoDirectory() string {
}

func (c *Config) sanitize() {
c.GithubUsername = sanitizeField(c.GithubUsername)
c.APIKey = sanitizeField(c.APIKey)
c.ExercismDirectory = sanitizeField(c.ExercismDirectory)
c.Hostname = sanitizeField(c.Hostname)
Expand Down
7 changes: 2 additions & 5 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func TestReadingWritingConfig(t *testing.T) {
assert.NoError(t, err)

c := &Config{
GithubUsername: "user",
APIKey: "MyKey",
ExercismDirectory: "/exercism/directory",
Hostname: "localhost",
Expand All @@ -62,9 +61,8 @@ func TestReadingWritingConfig(t *testing.T) {
}

func TestDecodingConfig(t *testing.T) {
unsanitizedJSON := `{"githubUsername":"user ","apiKey":"MyKey ","exercismDirectory":"/exercism/directory\r\n","hostname":"localhost \r\n"}`
unsanitizedJSON := `{"apiKey":"MyKey ","exercismDirectory":"/exercism/directory\r\n","hostname":"localhost \r\n"}`
sanitizedConfig := &Config{
GithubUsername: "user",
APIKey: "MyKey",
ExercismDirectory: "/exercism/directory",
Hostname: "localhost",
Expand All @@ -78,12 +76,11 @@ func TestDecodingConfig(t *testing.T) {

func TestEncodingConfig(t *testing.T) {
currentConfig := Config{
GithubUsername: "user\r\n",
APIKey: "MyKey ",
ExercismDirectory: "/home/user name ",
Hostname: "localhost ",
}
sanitizedJSON := `{"githubUsername":"user","apiKey":"MyKey","exercismDirectory":"/home/user name","hostname":"localhost"}
sanitizedJSON := `{"apiKey":"MyKey","exercismDirectory":"/home/user name","hostname":"localhost"}
`

buf := new(bytes.Buffer)
Expand Down
31 changes: 2 additions & 29 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,25 +321,6 @@ func main() {
fmt.Println("The last submission was successfully deleted.")
},
},
{
Name: "whoami",
ShortName: "w",
Usage: "Get the github username that you are logged in as",
Action: func(ctx *cli.Context) {
configPath := ctx.GlobalString("config")
c, err := config.FromFile(configPath)
if err != nil {
fmt.Println("Are you sure you are logged in? Please login again.")
c, err = login(configPath)
if err != nil {
fmt.Println(err)
return
}
}

fmt.Println(c.GithubUsername)
},
},
}
err := app.Run(os.Args)
if err != nil {
Expand Down Expand Up @@ -375,19 +356,13 @@ func absolutePath(path string) (string, error) {
}

func askForConfigInfo() (*config.Config, error) {
var un, key, dir string
var key, dir string
delim := "\r\n"

bio := bufio.NewReader(os.Stdin)

fmt.Print("Your GitHub username: ")
un, err := bio.ReadString('\n')
if err != nil {
return nil, err
}

fmt.Print("Your Exercism API key (found at http://exercism.io/account): ")
key, err = bio.ReadString('\n')
key, err := bio.ReadString('\n')
if err != nil {
return nil, err
}
Expand All @@ -401,7 +376,6 @@ func askForConfigInfo() (*config.Config, error) {
}

key = strings.TrimRight(key, delim)
un = strings.TrimRight(un, delim)
dir = strings.TrimRight(dir, delim)

if dir == "" {
Expand All @@ -422,7 +396,6 @@ func askForConfigInfo() (*config.Config, error) {
}

return &config.Config{
GithubUsername: un,
APIKey: key,
ExercismDirectory: dir,
Hostname: "http://exercism.io",
Expand Down
8 changes: 2 additions & 6 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ func TestLogoutDeletesConfigFile(t *testing.T) {

func TestAskForConfigInfoAllowsSpaces(t *testing.T) {
dirName := "dirname with spaces"
userName := "TestUsername"
apiKey := "abc123"

c := respondToAskForConfig(t, fmt.Sprintf("%s\r\n%s\r\n%s\r\n", userName, apiKey, dirName))
c := respondToAskForConfig(t, fmt.Sprintf("%s\r\n%s\r\n", apiKey, dirName))
absoluteDirName, _ := absolutePath(dirName)
_, err := os.Stat(absoluteDirName)
if err != nil {
Expand All @@ -48,16 +47,14 @@ func TestAskForConfigInfoAllowsSpaces(t *testing.T) {
os.Remove(absoluteDirName)

assert.Equal(t, c.ExercismDirectory, absoluteDirName)
assert.Equal(t, c.GithubUsername, userName)
assert.Equal(t, c.APIKey, apiKey)
}

func TestAskForConfigInfoDefaultPath(t *testing.T) {
dirName := ""
userName := "TestUsername"
apiKey := "abc123"

c := respondToAskForConfig(t, fmt.Sprintf("%s\r\n%s\r\n%s\r\n", userName, apiKey, dirName))
c := respondToAskForConfig(t, fmt.Sprintf("%s\r\n%s\r\n", apiKey, dirName))
absoluteDirName := config.DefaultAssignmentPath()
_, err := os.Stat(absoluteDirName)
if err != nil {
Expand All @@ -66,7 +63,6 @@ func TestAskForConfigInfoDefaultPath(t *testing.T) {
os.Remove(absoluteDirName)

assert.Equal(t, c.ExercismDirectory, absoluteDirName)
assert.Equal(t, c.GithubUsername, userName)
assert.Equal(t, c.APIKey, apiKey)
}

Expand Down

0 comments on commit 07cc334

Please sign in to comment.