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

Improve gno run #930

Open
moul opened this issue Jun 22, 2023 · 8 comments
Open

Improve gno run #930

moul opened this issue Jun 22, 2023 · 8 comments
Labels
🗺️good first issue🗺️ Ideal for newcomer contributors help wanted Want to contribute? We recommend these issues.

Comments

@moul
Copy link
Member

moul commented Jun 22, 2023

The gno run command is presently in a pre-alpha phase and may not perform reliably due to its specific requirements for package and function naming.

Its primary objective is to facilitate a smooth transition for developers from Go by allowing them to start with a basic main function. Additionally, it aims to provide utility tools for those who are forking or reviewing a package.

To enhance its usability and commence documentation in guides, two primary enhancements are urgently needed:

  1. The inclusion of argument passing support akin to os.Args, enabling more dynamic results from a single main function based on various parameters.
  2. Increased flexibility in the package PKGPATH specification, making it easier to add a main function and execute gno run on a package without having to specify a file (related to issue Allow *_test.gno file to run pkg with _test as suffix #768).

Addresses #972

@moul moul added 🗺️good first issue🗺️ Ideal for newcomer contributors help wanted labels Jun 22, 2023
@ajnavarro
Copy link
Contributor

ajnavarro commented Jun 26, 2023

Starting with the implementation of the first enhancement (os.Args).

@ajnavarro
Copy link
Contributor

I refactored the RunMain() method to accept a slice of arguments. Apart from that, I added the os package into the stdlibs gnovm folder.

stdlib is loaded when using VMKeeper but RunMain() is on the Machine struct, so it looks a bit strange that to make Args work, you need to use the VM through the VMKeeper.

I'm having some problems injecting the Args into a var inside a package, waiting for #859 which should make the process simpler.

If someone has some insights about how to move forward, I'd be willing to chat with you about it.

@moul
Copy link
Member Author

moul commented Jul 13, 2023

Do you already have a PR for your work? can you share, the link?

@ajnavarro
Copy link
Contributor

@moul I don't. Because I wasn't able to make it work, I just discarded the changes. I can recreate and add them to a draft PR.

@moul
Copy link
Member Author

moul commented Jul 17, 2023

Yes please, a draft PR may be useful to help you.

@ajnavarro
Copy link
Contributor

@moul This is what I was trying to do: #982

@moul moul moved this to 🌟 Wanted for Launch in 🚀 The Launch [DEPRECATED] Sep 5, 2023
@moul moul added this to the 🌟 main.gno.land (wanted) milestone Sep 8, 2023
@moul moul moved this to Todo in 💪 Bounties & Worx Dec 22, 2023
@Kouteki Kouteki added help wanted Want to contribute? We recommend these issues. and removed help wanted labels Oct 2, 2024
@wyhaines wyhaines added the hacktoberfest This might be a good issue for a hacktoberfest participant to handle. label Oct 7, 2024
@salihdhaifullah
Copy link

I have a question how is the arguments will be parsed ?
currently when you try to pass arguments after/before the file name it will be treated as a file, for example when i run

gno run main.gno hello

I get stat hello: no such file or directory
how do you want to handle this, do you want to handle this using a flag for example

gno run main.gno  --args="Hello World"

or put the files under a flag

gno run  --files="main.gno test.gno" Hello World

@thehowl
Copy link
Member

thehowl commented Oct 21, 2024

I discussed with @moul how to have os.Args in a "nice" way. Thanks for your contribution @salihdhaifullah, but actually direct access to os.Args is a non-goal.

Essentially we want main() as a way to access a realm / package from the GnoVM in an "interactive" way from the command line. There is already a way to have this - using gno run -expr, which allows to pass in an arbitrary expression to execute in place of main(); but we can "evolve" the usage of main to become a CLI "inspector" tool. Possibly in conjuction with #2989.

So, we're thinking of changing the functioning of gno run to be as follows:

gno run <PATH> [<ARGUMENT>...]

instead of supporting multiple file arguments.

Then, if arguments are passed, they are given in to the main function; in a fashion similar to what we have for maketx call. For example:

gno run . hello world
func main(arg1, arg2 string) {
    println(arg1, arg2)
}

will print hello world.

@wyhaines wyhaines removed the hacktoberfest This might be a good issue for a hacktoberfest participant to handle. label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗺️good first issue🗺️ Ideal for newcomer contributors help wanted Want to contribute? We recommend these issues.
Projects
Status: Todo
Status: 🌟 Wanted for Launch
Development

No branches or pull requests

6 participants