-
Notifications
You must be signed in to change notification settings - Fork 192
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
Add Support for Example Code #1026
base: master
Are you sure you want to change the base?
Conversation
This reverts commit 2332758.
This is cool, but is effectively a shortcut for I think a more interesting implementation would be implementing support for a command which initialises a script based on an example from a named package. Something like: $ nimble init-example pkgName/exampleName # creates a exampleName.nim file in the CWD ready to be compiled/edited |
That's true, but one package might require you to do I think it's worth noting here that the Nimble readme doesn't actually say exactly where your example code is supposed to go, nor does |
@dom96 I played around with it a bit, and it isn't possible to do However... Are the There might be a lot of cool things Nimble could do with examples (like your |
Think would be awesome Would also remove the need for writing custom tools like logue and nicoboot |
I've thought about this for a few weeks, and I have some thoughts for how I could make this better: Things to remove: Right now, Things to add: Some way to quickly copy/run examples from Nimble packages. Here is my idea:
|
@dom96 Nimble does not provide an automated way to generate, package and install developer documentation. Having an examplesDir variable would be a step in the right direction. |
This PR adds features for building/running example code.
Rationale
Example code is awesome.
A lot of Nimble packages rely on example code in lieu of extensive documentation. However, different packages structure their examples in different ways, so users have to figure out how to compile/run the examples first. By providing support for example code inside of Nimble, we can create a de facto standard structure for example code, making the Nim ecosystem more accessible.
.nimble files already have a
bin
variable that contains a list of executables that can be built from the Nimble package. Example code could be added to a Nimble package usingbin
. However, this is bad practice because the examples could be installed to a user's machine usingnimble install
. Obviously, installation isn't desirable for example code.Changes
New
examplesDir
.nimble variableA new variable has been added to the .nimble file:
examplesDir
. It works similarly tosrcDir
andbinDir
, except sequences aren't allowed.examplesDir
tells Nimble which folder contains the example code.If
examplesDir
is not specified, its value is assumed to be"examples"
.New
--example
command-line argumentA new command line argument has been added:
--example
. It can be used on therun
,build
,js
,cc
, andc
commands.When
--example
is specified, these commands will search for the target file inside of the example directory, instead of searching through the package itself.Examples:
New
nimble init
behavior for library and hybrid projectsFor library and hybrid projects, the .nimble file generated by
nimble init
will now include this line:# examplesDir = "examples" # Uncomment to change the name of the examples directory
examplesDir
is commented out for two reasons:New library projects will now include this file, located at
examples/example1.nim
:New hybrid projects will now include this file, located at
examples/example1.nim
:Example
To try out this feature on the fly: