Skip to content

Commit fb49175

Browse files
creekorfulanthonyfok
authored andcommitted
Implement clone command
1 parent 1e46a29 commit fb49175

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

clone.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"log"
7+
"os"
8+
"os/exec"
9+
)
10+
11+
func execClone(args []string) {
12+
fs := flag.NewFlagSet("clone", flag.ExitOnError)
13+
14+
fs.Usage = func() {
15+
fmt.Fprintf(os.Stderr, "Usage: %s clone <package-name>\n", os.Args[0])
16+
fmt.Fprintf(os.Stderr, "Clone a Go package from Salsa\n"+
17+
"and download the appropriate tarball.\n")
18+
fmt.Fprintf(os.Stderr, "Example: %s clone golang-github-mmcdole-goxpp\n", os.Args[0])
19+
}
20+
21+
err := fs.Parse(args)
22+
if err != nil {
23+
log.Fatalf("parse args: %s", err)
24+
}
25+
26+
if fs.NArg() != 1 {
27+
fs.Usage()
28+
os.Exit(1)
29+
}
30+
31+
cmd := exec.Command("gbp", "clone", fmt.Sprintf("vcsgit:%s", fs.Arg(0)), "--postclone=origtargz")
32+
cmd.Stderr = os.Stderr
33+
if err := cmd.Run(); err != nil {
34+
log.Fatalf("Could not run %v: %v", cmd.Args, err)
35+
}
36+
37+
fmt.Printf("Successfully cloned %s\n", fs.Arg(0))
38+
}

main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func usage() {
2626
fmt.Fprintf(os.Stderr, "\tsearch\t\t\tsearch Debian for already-existing packages\n")
2727
fmt.Fprintf(os.Stderr, "\testimate\t\testimate the amount of work for a package\n")
2828
fmt.Fprintf(os.Stderr, "\tcreate-salsa-project\tcreate a project for hosting Debian packaging\n")
29+
fmt.Fprintf(os.Stderr, "\tclone\t\t\tclone a Go package from Salsa\n")
2930
fmt.Fprintf(os.Stderr, "\n")
3031
fmt.Fprintf(os.Stderr, "For backwards compatibility, when no command is specified,\nthe make command is executed.\n")
3132
fmt.Fprintf(os.Stderr, "\n")
@@ -62,6 +63,8 @@ func main() {
6263
execEstimate(args[1:])
6364
case "make":
6465
execMake(args[1:], nil)
66+
case "clone":
67+
execClone(args[1:])
6568
default:
6669
// redirect -help to the global usage
6770
execMake(args, usage)

0 commit comments

Comments
 (0)