Skip to content

Commit b602715

Browse files
authored
refactor minor things in the modules chapter (#915)
1 parent 6e1eda7 commit b602715

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

book/modules.md

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ then
7878

7979
The result should be similar as in the previous section.
8080

81-
Note that the `use greetings.nu hello` call here first implicitly creates the `greetings` module, then takes `hello` from it. You could also write it as `module greetings.nu`, `use greetings hello`. Using `module` can be useful if you're not interested in any definitions from the module but want to, e.g., re-export the module (`export module greetings.nu`).
81+
> **Note**
82+
> that the `use greetings.nu hello` call here first implicitly creates the `greetings` module,
83+
> then takes `hello` from it. You could also write it as `module greetings.nu`, `use greetings hello`.
84+
> Using `module` can be useful if you're not interested in any definitions from the module but want to,
85+
> e.g., re-export the module (`export module greetings.nu`).
8286
8387
## Modules from directories
8488

@@ -119,21 +123,29 @@ The import pattern has the following structure `use head members...` where `head
119123

120124
Using our `greetings` example:
121125

122-
`use greetings`
126+
```
127+
use greetings
128+
```
123129

124-
Imports all symbols with prefixed with the `greetings` namespace (can call `greetings hello` and `greetings hi`).
130+
imports all symbols prefixed with the `greetings` namespace (can call `greetings hello` and `greetings hi`).
125131

126-
`use greetings hello`
132+
```
133+
use greetings hello
134+
```
127135

128-
The `hello` command will be imported directly without any prefix.
136+
will import the `hello` command directly without any prefix.
129137

130-
`use greetings [ hello, hi ]`
138+
```
139+
use greetings [hello, hi]
140+
```
131141

132-
Imports multiple definitions<> directly without any prefix.
142+
imports multiple definitions<> directly without any prefix.
133143

134-
`use greetings *`
144+
```
145+
use greetings *
146+
```
135147

136-
You can also use the module name and the `*` glob to import all names directly without any prefix.
148+
will import all names directly without any prefix.
137149

138150
## `main`
139151

@@ -185,7 +197,8 @@ Submodules are modules inside modules. They are automatically created when you c
185197

186198
The difference is that `export module some-module` _only_ adds the module as a submodule, while `export use some-module` _also_ re-exports the submodule's definitions. Since definitions of submodules are available when importing from a module, `export use some-module` is typically redundant, unless you want to re-export its definitions without the namespace prefix.
187199

188-
_Note: `module` without `export` defines only a local module, it does not export a submodule._
200+
> **Note**
201+
> `module` without `export` defines only a local module, it does not export a submodule.
189202
190203
Let's illustrate this with an example. Assume three files:
191204

@@ -403,7 +416,8 @@ hi there!
403416

404417
Since directories can be imported as submodules and submodules can naturally form subcommands it is easy to build even complex command line applications with a simple file structure.
405418

406-
_WIP_
419+
> **Warning**
420+
> Work In Progress
407421
408422
### Dumping files into directory
409423

@@ -449,7 +463,8 @@ We use it in our official virtualenv integration https://github.com/pypa/virtual
449463

450464
Another example could be our unofficial Conda module: https://github.com/nushell/nu_scripts/blob/f86a060c10f132407694e9ba0f536bfe3ee51efc/modules/virtual_environments/conda.nu
451465

452-
_WIP_
466+
> **Warning**
467+
> Work In Progress
453468
454469
## Hiding
455470

@@ -488,4 +503,5 @@ It can be one of the following:
488503

489504
- Hides all of the module's exports, without the prefix
490505

491-
_Note: `hide` is not a supported keyword at the root of the module (unlike `def` etc.)_
506+
> **Note**
507+
> `hide` is not a supported keyword at the root of the module (unlike `def` etc.)

0 commit comments

Comments
 (0)