-
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.
- Loading branch information
0 parents
commit 8490f6f
Showing
8 changed files
with
291 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
gill | ||
dist/ |
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,21 @@ | ||
VERSION = `awk '/VERSION/ { gsub("\"", ""); print $$NF }' $(CURDIR)/lib/version.go` | ||
DIST_DIR = $(CURDIR)/dist | ||
|
||
# | ||
# Packaging options | ||
# | ||
XC_ARCH ?= "386 amd64 arm" | ||
XC_OS ?= "darwin linux freebsd openbsd" | ||
|
||
build: clean | ||
go build | ||
|
||
clean: | ||
rm -rf gill | ||
|
||
package: | ||
@(echo $(VERSION)) | ||
@(go get github.com/laher/goxc) | ||
@($(GOPATH)/bin/goxc -arch=$(XC_ARCH) -os=$(XC_OS) -pv=$(VERSION) -d=$(DIST_DIR)) | ||
|
||
.PHONY: install |
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,43 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/codegangsta/cli" | ||
"github.com/mephux/gill/lib" | ||
"github.com/sbinet/go-config/config" | ||
"log" | ||
"os" | ||
"os/user" | ||
"path" | ||
) | ||
|
||
func main() { | ||
app := cli.NewApp() | ||
|
||
app.Name = "gill" | ||
app.Usage = "Git, Clone, Cleanliness." | ||
app.Version = gill.GILL_VERSION | ||
app.Commands = []cli.Command{ | ||
gill.AddCommand(), | ||
gill.RemoveCommand(), | ||
gill.ListCommand(), | ||
gill.ConfigCommand(), | ||
} | ||
|
||
usr, err := user.Current() | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
config_path := path.Join(usr.HomeDir, gill.CONFIG_FILENAME) | ||
|
||
if _, err := os.Stat(config_path); err != nil { | ||
c := config.NewDefault() | ||
c.AddSection("Paths") | ||
c.AddSection("Repos") | ||
c.AddOption("Paths", "source", path.Join(usr.HomeDir, "Source")) | ||
c.WriteFile(config_path, 0644, "Gill - Git, Clone, Cleanliness.") | ||
} | ||
|
||
app.Run(os.Args) | ||
} |
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,137 @@ | ||
package gill | ||
|
||
import ( | ||
"fmt" | ||
"github.com/codegangsta/cli" | ||
"github.com/sbinet/go-config/config" | ||
"log" | ||
"os" | ||
"os/user" | ||
"net/url" | ||
"regexp" | ||
"path" | ||
"path/filepath" | ||
) | ||
|
||
// hasExpectedArgs checks whether the number of args are as expected. | ||
func hasArgs(args []string, expected int) bool { | ||
switch expected { | ||
case -1: | ||
if len(args) > 0 { | ||
return true | ||
} else { | ||
return false | ||
} | ||
default: | ||
if len(args) == expected { | ||
return true | ||
} else { | ||
return false | ||
} | ||
} | ||
} | ||
|
||
func getConfigPath() string { | ||
usr, err := user.Current() | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
return path.Join(usr.HomeDir, CONFIG_FILENAME) | ||
} | ||
|
||
func getConfig(config_path string) (*config.Config, error) { | ||
return config.ReadDefault(config_path) | ||
} | ||
|
||
// Edit Configuration | ||
func ConfigAction(c *cli.Context) { | ||
if !hasArgs(c.Args(), 2) { | ||
log.Fatal("Incorrect number of arguments to 'config' command") | ||
} | ||
|
||
config_path := getConfigPath() | ||
d, _ := getConfig(config_path) | ||
|
||
fmt.Println("WORD:", config_path, d) | ||
|
||
key := c.Args()[0] | ||
value := c.Args()[1] | ||
|
||
// TODO - Switch for different config key types | ||
if !filepath.IsAbs(value) { | ||
abs_path, err := filepath.Abs(value) | ||
if err != nil { | ||
log.Fatal("Incorrect config value.") | ||
} | ||
value = abs_path | ||
} | ||
|
||
fmt.Println(key, value) | ||
|
||
d.AddOption("Paths", key, value) | ||
d.WriteFile(config_path, 0644, "Gill - Git, Clone, Cleanliness.") | ||
} | ||
|
||
// Reove | ||
func RemoveAction(c *cli.Context) { | ||
config_path := getConfigPath() | ||
d, _ := getConfig(config_path) | ||
|
||
RemoveRepo(config_path, d) | ||
} | ||
|
||
// List | ||
func ListAction(c *cli.Context) { | ||
config_path := getConfigPath() | ||
d, _ := getConfig(config_path) | ||
|
||
if d.HasSection("Repos") { | ||
repos, _ := d.Options("Repos") | ||
|
||
for i := 0; i < len(repos); i++ { | ||
fmt.Println(repos[i]) | ||
} | ||
|
||
} else { | ||
d.AddSection("Repos") | ||
fmt.Println("No repositories have been added to your gill store.") | ||
os.Exit(1) | ||
} | ||
|
||
} | ||
|
||
// Add | ||
func AddAction(c *cli.Context) { | ||
if !hasArgs(c.Args(), 1) { | ||
log.Fatal("Incorrect number of arguments to 'add' command") | ||
} | ||
|
||
gill_url, err := url.Parse(c.Args()[0]) | ||
|
||
if err != nil { | ||
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) | ||
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) | ||
} | ||
|
||
} |
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,4 @@ | ||
package gill | ||
|
||
const GILL_VERSION = "0.1.0" | ||
const CONFIG_FILENAME = ".gill" |
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,44 @@ | ||
package gill | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"github.com/sbinet/go-config/config" | ||
"regexp" | ||
"strings" | ||
"path" | ||
"log" | ||
) | ||
|
||
func FetchRepo(config_path string, u *url.URL, d *config.Config) { | ||
|
||
reg, err := regexp.Compile("(.git)$") | ||
split := strings.Split(u.Path, "/") | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
key := reg.ReplaceAllString(split[len(split) - 1], "") | ||
|
||
if len(u.Fragment) > 0 { | ||
key = path.Join(u.Fragment, key) | ||
} | ||
|
||
source_path, _ := d.String("Paths", "source") | ||
|
||
fmt.Println("key:", key, source_path) | ||
|
||
fmt.Println("Word, In Fetch", key, d) | ||
|
||
if !d.HasSection("Repos") { | ||
d.AddSection("Repos") | ||
} | ||
|
||
d.AddOption("Repos", key, path.Join(source_path, key)) | ||
d.WriteFile(config_path, 0644, "Gill - Git, Clone, Cleanliness.") | ||
} | ||
|
||
func RemoveRepo(config_path string, d *config.Config) { | ||
fmt.Println("REMOVE") | ||
} |
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,37 @@ | ||
package gill | ||
|
||
import ( | ||
"github.com/codegangsta/cli" | ||
) | ||
|
||
func AddCommand() cli.Command { | ||
return cli.Command{ | ||
Name: "add", | ||
Usage: "Add a git repository to your gill store.", | ||
Action: AddAction, | ||
} | ||
} | ||
|
||
func RemoveCommand() cli.Command { | ||
return cli.Command{ | ||
Name: "remove", | ||
Usage: "Remove a git repository from your gill store.", | ||
Action: RemoveAction, | ||
} | ||
} | ||
|
||
func ListCommand() cli.Command { | ||
return cli.Command{ | ||
Name: "list", | ||
Usage: "List all git repositories in your gill store.", | ||
Action: ListAction, | ||
} | ||
} | ||
|
||
func ConfigCommand() cli.Command { | ||
return cli.Command{ | ||
Name: "config", | ||
Usage: "Set gill configuration options. Example: gill config source ~/Source", | ||
Action: ConfigAction, | ||
} | ||
} |
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,3 @@ | ||
package gill | ||
|
||
const VERSION = "0.1.0" |