Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit 591aabd

Browse files
author
Eric Crosson
committed
Initial commit
0 parents  commit 591aabd

File tree

6 files changed

+154
-0
lines changed

6 files changed

+154
-0
lines changed

src/cmd/git-ledger/add.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/urfave/cli"
8+
// "github.com/BurntSushi/toml"
9+
"github.com/ericcrosson/git-ledger/src/git-ledger"
10+
"github.com/codeskyblue/go-sh"
11+
)
12+
13+
func getRemote(dir string) string {
14+
session := sh.NewSession()
15+
session.SetDir(dir)
16+
remoteRaw, err := session.Command("git", "remote").Command("head", "-n", "1").Output()
17+
if err != nil {
18+
panic(err)
19+
}
20+
return strings.TrimSpace(fmt.Sprintf("%s", remoteRaw))
21+
}
22+
23+
func getSlug(dir string) string {
24+
session := sh.NewSession()
25+
session.SetDir(dir)
26+
out, err := session.Command("git", "remote", "get-url", getRemote(dir)).Command("sed", "-r", "s#[^/:]*/##").Output()
27+
output := strings.TrimSpace(fmt.Sprintf("%s", out))
28+
if err != nil {
29+
panic(err)
30+
}
31+
return output
32+
}
33+
34+
func add(c *cli.Context) error {
35+
fmt.Println("I am in add!")
36+
// Default: add cwd to toml
37+
project := c.Args().First()
38+
39+
// TODO: clean up this declaration
40+
var record ledger.Record
41+
record.Path = project
42+
record.Slug = getSlug(project)
43+
44+
fmt.Println("record is ", record)
45+
fmt.Println("path is ", ledger.Path())
46+
47+
return nil
48+
}

src/cmd/git-ledger/find.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/urfave/cli"
7+
)
8+
9+
func find(c *cli.Context) error {
10+
fmt.Println("I am in find!")
11+
return nil
12+
}

src/cmd/git-ledger/ls.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/urfave/cli"
7+
)
8+
9+
func ls(c *cli.Context) error {
10+
fmt.Println("I am in ls!")
11+
return nil
12+
}

src/cmd/git-ledger/main.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package main
2+
3+
import (
4+
"os"
5+
"fmt"
6+
7+
"github.com/Masterminds/semver"
8+
"github.com/jmalloc/grit/src/grit/pathutil"
9+
"github.com/urfave/cli"
10+
)
11+
12+
var VERSION = semver.MustParse("0.0.0")
13+
14+
func main () {
15+
16+
app := cli.NewApp()
17+
homeDir, _ := pathutil.HomeDir()
18+
19+
app.Name = "grip"
20+
app.Usage = "Index your Git clones."
21+
app.Version = VERSION.String()
22+
23+
app.Commands = []cli.Command {
24+
{
25+
Name: "add",
26+
Usage: "Start tracking an existing repository.",
27+
ArgsUsage: "[<path>]",
28+
Action: add,
29+
},
30+
{
31+
Name: "find",
32+
Usage: "Print the location of a tracked repository.",
33+
ArgsUsage: "[<path>]",
34+
Action: find,
35+
},
36+
{
37+
Name: "ls",
38+
Usage: "Print all tracked repositories",
39+
Action: find,
40+
},
41+
{
42+
Name: "rm",
43+
Usage: "Stop tracking an existing repository.",
44+
ArgsUsage: "[<path>]",
45+
Action: rm,
46+
},
47+
}
48+
49+
fmt.Println("Made it here with homeDir ", homeDir)
50+
51+
if err := app.Run(os.Args); err != nil {
52+
os.Exit(1)
53+
}
54+
}

src/cmd/git-ledger/rm.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/urfave/cli"
7+
)
8+
9+
func rm(c *cli.Context) error {
10+
fmt.Println("I am in rm!")
11+
return nil
12+
}

src/git-ledger/ledger.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package ledger
2+
3+
import (
4+
"path"
5+
"github.com/jmalloc/grit/src/grit/pathutil"
6+
)
7+
8+
type Record struct {
9+
Path string
10+
Slug string
11+
}
12+
13+
func Path() string {
14+
home, _ := pathutil.HomeDir()
15+
return path.Join(home, ".git-ledger")
16+
}

0 commit comments

Comments
 (0)