Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cobra init on new empty project, got undeclared name: cmd on gotype #432

Closed
zer09 opened this issue May 1, 2017 · 10 comments
Closed

cobra init on new empty project, got undeclared name: cmd on gotype #432

zer09 opened this issue May 1, 2017 · 10 comments

Comments

@zer09
Copy link

zer09 commented May 1, 2017

Hello good day,

I just want to ask for help, When I do cobra init to start a new project, it will create the but opining the main.go or executing gotype main.go I will got this.
main.go:17:8: could not import sample_proj/cmd (can't find import: sample_proj/cmd)
main.go:20:2: undeclared name: cmd

Thanks

@n10v
Copy link
Collaborator

n10v commented May 1, 2017

Hello!
I think, it's because of underscore.
Can you please describe step-by-step, what did you do, with which arguments did you executed cobra init, and content of main.go.

@zer09
Copy link
Author

zer09 commented May 2, 2017

@BoGeM Sorry it takes me long time to reply.

I recreate it, on the go src directory I create a new folder then inside there, just execute cobra init then execute gotype pointing to main.go and got the same result.

I include a print screen of it.
untitled

And the content of the main.go is this.
// Copyright © 2017 NAME HERE <EMAIL ADDRESS>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import "samp/cmd"

func main() {
cmd.Execute()
}
`

@n10v
Copy link
Collaborator

n10v commented May 2, 2017

And could you please write a content of samp\cmd\root.go?

@zer09
Copy link
Author

zer09 commented May 2, 2017

@BoGeM here is the content of the root.go I put it on gist.

@n10v
Copy link
Collaborator

n10v commented May 2, 2017

I understood, what's the problem.
The problem is in incorrect folder layout of your project.
Instead of F:GO\src\samp try to initialize the project in F:GO\src\github.com\zer09\samp. More about project organisation here.

@zer09
Copy link
Author

zer09 commented May 2, 2017

Sorry to bother you so much, I pulling my hair right now, but I still get the same result.
untitled

@n10v
Copy link
Collaborator

n10v commented May 2, 2017

No problem!
Send me please main.go and cmd\root.go.
Did you try to execute go run main.go?

@zer09
Copy link
Author

zer09 commented May 2, 2017

Yes i did, and execute successfully. but my editor is keep complaining about it.
here is the files cobra test

Thanks

@n10v
Copy link
Collaborator

n10v commented May 2, 2017

I became the same issue with gotype, but then I executed go install, this issue is gone.
The problem is in gotype, not in cobra.

@zer09
Copy link
Author

zer09 commented May 2, 2017

hmm that was odd. I also do go install and the error was gone for that sample code, but running again gotype to other sample code the error still showing, until I do go install.

@n10v n10v closed this as completed May 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants