-
Notifications
You must be signed in to change notification settings - Fork 373
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
feat: implement gno mod init
command
#955
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 💯
Really welcoming this feature 🚀
gnovm/cmd/gno/mod.go
Outdated
ShortUsage: "init [module-path]", | ||
ShortHelp: "Initialize gno.mod file in current directory", | ||
}, | ||
nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: you can use commands.NewEmptyConfig()
, as with other commands that don't have a config file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done: 791996d
modPath = string(pkgName) | ||
} | ||
|
||
modFile := &File{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not create a helper for this initialization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I agree there is a helper needed for File
initialization.
I plan to refactor code and define methods for File
. like for this specific case modFile.AddModuleStmt()
.
Will do it in the another PR.
if pkgName == "" { | ||
return errors.New("cannot determine package name") | ||
} | ||
modPath = string(pkgName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this situation when pkgName == """
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
Should be fixed by: fa7fc5a
gnovm/pkg/gnomod/gnomod_test.go
Outdated
// Verify gno.mod file | ||
bz, err := os.ReadFile(filepath.Join(dirPath, "gno.mod")) | ||
assert.NoError(t, err) | ||
assert.Equal(t, string(bz), tc.out) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second param for assert.Equal
is the expected
, not the actual
(so the params should be switched)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCreateGnoModFile(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you paralellize this test with t.Parallel()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done efc2e5b
121be82
to
7807a32
Compare
|
||
var pkgName gnolang.Name | ||
for _, file := range files { | ||
if file.IsDir() || !strings.HasSuffix(file.Name(), ".gno") || strings.HasSuffix(file.Name(), "_filetest.gno") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should create helpers for this in another PR. Also discussed with @tbruyelle in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Will open PR for that soon.
Implement `gno mod init` command. Usage: ```sh $ gno mod init <module-path> ``` If no `<module-path>` is given, tries to determine package name from existing `*.gno` files. <details><summary>Checklists...</summary> ## Contributors Checklist - [x] Added new tests, or not needed, or not feasible - [x] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [x] Updated the official documentation or not needed - [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [ ] Added references to related issues and PRs - [x] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](../.benchmarks/README.md). ## Maintainers Checklist - [x] Checked that the author followed the guidelines in `CONTRIBUTING.md` - [x] Checked the conventional-commit (especially PR title and verb, presence of `BREAKING CHANGE:` in the body) - [x] Ensured that this PR is not a significant change or confirmed that the review/consideration process was appropriate for the change </details>
Implement
gno mod init
command.Usage:
If no
<module-path>
is given, tries to determine package name from existing*.gno
files.Checklists...
Contributors Checklist
BREAKING CHANGE: xxx
message was included in the descriptionMaintainers Checklist
CONTRIBUTING.md
BREAKING CHANGE:
in the body)