Browse Source

Fixed conflicts

pull/103/head
Unknown 12 years ago
parent
commit
9161281845
  1. 59
      cmd/cmd.go
  2. 2
      cmd/gen.go
  3. 10
      cmd/get.go
  4. 2
      cmd/repos.go
  5. 60
      gopm.go

59
cmd/cmd.go

@ -0,0 +1,59 @@
package cmd
import (
"flag"
"fmt"
"os"
"strings"
)
var (
reposDir string = "~/.gopm/repos"
)
// A Command is an implementation of a go command
// like go build or go fix.
type Command struct {
// Run runs the command.
// The args are the arguments after the command name.
Run func(cmd *Command, args []string)
// UsageLine is the one-line usage message.
// The first word in the line is taken to be the command name.
UsageLine string
// Short is the short description shown in the 'go help' output.
Short string
// Long is the long message shown in the 'go help <this-command>' output.
Long string
// Flag is a set of flags specific to this command.
Flag flag.FlagSet
// CustomFlags indicates that the command will do its own
// flag parsing.
CustomFlags bool
}
// Name returns the command's name: the first word in the usage line.
func (c *Command) Name() string {
name := c.UsageLine
i := strings.Index(name, " ")
if i >= 0 {
name = name[:i]
}
return name
}
func (c *Command) Usage() {
fmt.Fprintf(os.Stderr, "usage: %s\n\n", c.UsageLine)
fmt.Fprintf(os.Stderr, "%s\n", strings.TrimSpace(c.Long))
os.Exit(2)
}
// Runnable reports whether the command can be run; otherwise
// it is a documentation pseudo-command such as importpath.
func (c *Command) Runnable() bool {
return c.Run != nil
}

2
cmd/gen.go

@ -1,4 +1,4 @@
package main
package cmd
// scan a directory and gen a gopm file
func gen(dir string) {

10
cmd/get.go

@ -1,4 +1,4 @@
package main
package cmd
import (
"fmt"
@ -11,7 +11,7 @@ import (
"strings"
)
var cmdGet = &Command{
var CmdGet = &Command{
UsageLine: "get [-u] [packages]",
Short: "download and install packages and dependencies",
Long: `
@ -46,11 +46,11 @@ See also: go build, go install, go clean.
`,
}
var getD = cmdGet.Flag.Bool("f", false, "")
var getU = cmdGet.Flag.Bool("u", false, "")
var getD = CmdGet.Flag.Bool("f", false, "")
var getU = CmdGet.Flag.Bool("u", false, "")
func init() {
cmdGet.Run = runGet
CmdGet.Run = runGet
}
func runGet(cmd *Command, args []string) {

2
cmd/repos.go

@ -1,4 +1,4 @@
package main
package cmd
type Repos interface {
Url(pkgName string, ver string) string

60
main.go → gopm.go

@ -22,70 +22,24 @@ import (
"text/template"
"unicode"
"unicode/utf8"
"github.com/gpmgo/gopm/cmd"
)
var (
config map[string]interface{}
reposDir string = "~/.gopm/repos"
config map[string]interface{}
)
// A Command is an implementation of a go command
// like go build or go fix.
type Command struct {
// Run runs the command.
// The args are the arguments after the command name.
Run func(cmd *Command, args []string)
// UsageLine is the one-line usage message.
// The first word in the line is taken to be the command name.
UsageLine string
// Short is the short description shown in the 'go help' output.
Short string
// Long is the long message shown in the 'go help <this-command>' output.
Long string
// Flag is a set of flags specific to this command.
Flag flag.FlagSet
// CustomFlags indicates that the command will do its own
// flag parsing.
CustomFlags bool
}
// Name returns the command's name: the first word in the usage line.
func (c *Command) Name() string {
name := c.UsageLine
i := strings.Index(name, " ")
if i >= 0 {
name = name[:i]
}
return name
}
func (c *Command) Usage() {
fmt.Fprintf(os.Stderr, "usage: %s\n\n", c.UsageLine)
fmt.Fprintf(os.Stderr, "%s\n", strings.TrimSpace(c.Long))
os.Exit(2)
}
// Runnable reports whether the command can be run; otherwise
// it is a documentation pseudo-command such as importpath.
func (c *Command) Runnable() bool {
return c.Run != nil
}
// Commands lists the available commands and help topics.
// The order here is the order in which they are printed by 'go help'.
var commands = []*Command{
var commands = []*cmd.Command{
/*cmdBuild,
cmdClean,
cmdDoc,
cmdEnv,
cmdFix,
cmdFmt,*/
cmdGet,
cmd.CmdGet,
/*cmdInstall,
cmdList,
cmdRun,
@ -267,8 +221,8 @@ func help(args []string) {
if arg == "documentation" {
buf := new(bytes.Buffer)
printUsage(buf)
usage := &Command{Long: buf.String()}
tmpl(os.Stdout, documentationTemplate, append([]*Command{usage}, commands...))
usage := &cmd.Command{Long: buf.String()}
tmpl(os.Stdout, documentationTemplate, append([]*cmd.Command{usage}, commands...))
return
}
Loading…
Cancel
Save