Skip to content

Commit

Permalink
better parser
Browse files Browse the repository at this point in the history
  • Loading branch information
djcas9 committed Feb 6, 2014
1 parent acf0602 commit 1efd6b8
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 22 deletions.
25 changes: 7 additions & 18 deletions lib/actions.go
Expand Up @@ -67,7 +67,6 @@ func getConfig(config_path string) (Config, error) {
return config, errr
}

// Edit Configuration
func ConfigAction(c *cli.Context) {
if !hasArgs(c.Args(), 2) {
log.Fatal("Incorrect number of arguments to 'config' command")
Expand Down Expand Up @@ -138,24 +137,14 @@ func AddAction(c *cli.Context) {
log.Fatal("Unable to parse argument for 'add' command")
}

if gill_url.Scheme == "http" || gill_url.Scheme == "https" || gill_url.Scheme == "git" {
match, _ := regexp.MatchString(".git", gill_url.Path)

match, _ := regexp.MatchString(".git", gill_url.Path)
fmt.Println(match)

if !match {
log.Fatal("Unable to parse argument for 'add' command")
}

fmt.Println(gill_url.Host, gill_url.Path, err)

config_path := getConfigPath()
d, _ := getConfig(config_path)

FetchRepo(config_path, gill_url, d)

} else {
log.Fatalf("Unable to parse argument for 'add' command - Scheme '%s' not supported.", gill_url.Scheme)
if !match {
log.Fatal("Unable to parse argument for 'add' command")
}

config_path := getConfigPath()
d, _ := getConfig(config_path)

FetchRepo(config_path, gill_url, d)
}
62 changes: 58 additions & 4 deletions lib/fetch.go
Expand Up @@ -5,13 +5,67 @@ import (
// "log"
"net/url"
// "path"
// "regexp"
// "strings"
"strings"
)

func FetchRepo(config_path string, u *url.URL, d Config) {
fmt.Println(d)
fmt.Println("ADD")
fmt.Println(u.Scheme, u.Opaque, u.User, u.Host, u.Path, u.RawQuery, u.Fragment)

var username string

if len(u.Scheme) > 0 {

switch u.Scheme {
case "git":
var items []string = strings.Split(u.Path, "/")
u.Path = items[len(items)-1]
username = strings.Join(items[:len(items)-1], "/")
case "http", "https":
if len(u.Host) > 0 {
if strings.Contains(u.Host, ":") {
var items []string = strings.Split(u.Host, ":")
u.Host = items[0]
username = items[1]
} else {
var items []string = strings.Split(u.Path, "/")
fmt.Println("BEFORE:", items)

u.Path = items[len(items)-1]

for i := 0; i < len(items); i++ {
if len(items[i]) <= 0 {
items = append(items[:i], items[i+1:]...)
i--
}
}

username = items[0]
fmt.Println("AFTER", items)

}
}
}

} else {

if len(u.Path) > 0 && strings.Contains(u.Path, ":") {
var split []string = strings.Split(u.Path, ":")
var items []string = strings.Split(split[0], "@")
u.Host = items[1]

var userPath []string = strings.Split(split[1], "/")
username = userPath[0]
u.Path = userPath[1]
}

}

if u.Host == "github.com" {
// fetch json repo information
fmt.Println("fetch github information")
}

fmt.Println(u.Scheme, u.Opaque, u.User, username, u.Host, u.Path, u.RawQuery, u.Fragment)
}

func RemoveRepo(config_path string, d Config) {
Expand Down

0 comments on commit 1efd6b8

Please sign in to comment.