Myproject
---.idea
---scr
---cmd
---cmd.go
---test
---test.go
###POPATH 与 GOROOT
GOPATH="/Users/road/IdeaProjects/Myproject"
GOROOT="/usr/local/go"
package cmd
import (
"flag"
"fmt"
"os"
)
/*
jaca [-option] class [args...]
*/
type Cmd struct {
HelpFlag bool
VersionFlag bool
CpOption string
Class string
Args []string
}
func ParseCmd() *Cmd {
cmd := &Cmd{}
flag.Usage = PrintUsage
flag.BoolVar(&cmd.HelpFlag,"help",false,"print help message")
flag.BoolVar(&cmd.HelpFlag,"?",false,"print help message")
flag.BoolVar(&cmd.VersionFlag,"version",false,"print version and exit")
flag.StringVar(&cmd.CpOption,"cp","","classpth")
flag.StringVar(&cmd.CpOption,"classpath","","classpath")
flag.Parse();
}
func PrintUsage() {
fmt.Println("Ussge: %s [-option] class [args...]\n",os.Args[0])
}
package main
import (
"cmd"
)
func main() {
command := &Cmd{} //提示 unresolved type 'Cmd'
}
1
sryanyuan 2017-09-04 14:57:22 +08:00
command := &cmd.Cmd{}
|
2
nickname OP @sryanyuan 这样写还是不行,感觉是 import"cmd"并没有将自定义的 cmd 包导入到 test.go 中
|
3
sryanyuan 2017-09-04 16:31:22 +08:00
Myproject (GOPATH)下的 scr 是打错了?理论上应该是 src
命令行里直接 ``` export GOPATH=/Users/road/IdeaProjects/Myproject go install test ``` |
4
nickname OP @sryanyuan 是我敲错了,工程里是 src 没问题的
``` can't load package: package test: cannot find package "test" in any of: /usr/local/go/src/test (from $GOROOT) /Users/road/IdeaProjects/Myproject/src/test (from $GOPATH)``` |
5
nickname OP 在 StackOverflow 问了一下,标准库已经有一个同名的 cmd 包,跟我自定义的 cmd 包命名有冲突,我尝试改了名字,现在正常了
|