|
78 | 78 |
|
79 | 79 | The result should be similar as in the previous section.
|
80 | 80 |
|
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`). |
82 | 86 |
|
83 | 87 | ## Modules from directories
|
84 | 88 |
|
@@ -119,21 +123,29 @@ The import pattern has the following structure `use head members...` where `head
|
119 | 123 |
|
120 | 124 | Using our `greetings` example:
|
121 | 125 |
|
122 |
| -`use greetings` |
| 126 | +``` |
| 127 | +use greetings |
| 128 | +``` |
123 | 129 |
|
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`). |
125 | 131 |
|
126 |
| -`use greetings hello` |
| 132 | +``` |
| 133 | +use greetings hello |
| 134 | +``` |
127 | 135 |
|
128 |
| -The `hello` command will be imported directly without any prefix. |
| 136 | +will import the `hello` command directly without any prefix. |
129 | 137 |
|
130 |
| -`use greetings [ hello, hi ]` |
| 138 | +``` |
| 139 | +use greetings [hello, hi] |
| 140 | +``` |
131 | 141 |
|
132 |
| -Imports multiple definitions<> directly without any prefix. |
| 142 | +imports multiple definitions<> directly without any prefix. |
133 | 143 |
|
134 |
| -`use greetings *` |
| 144 | +``` |
| 145 | +use greetings * |
| 146 | +``` |
135 | 147 |
|
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. |
137 | 149 |
|
138 | 150 | ## `main`
|
139 | 151 |
|
@@ -185,7 +197,8 @@ Submodules are modules inside modules. They are automatically created when you c
|
185 | 197 |
|
186 | 198 | 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.
|
187 | 199 |
|
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. |
189 | 202 |
|
190 | 203 | Let's illustrate this with an example. Assume three files:
|
191 | 204 |
|
@@ -403,7 +416,8 @@ hi there!
|
403 | 416 |
|
404 | 417 | 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.
|
405 | 418 |
|
406 |
| -_WIP_ |
| 419 | +> **Warning** |
| 420 | +> Work In Progress |
407 | 421 |
|
408 | 422 | ### Dumping files into directory
|
409 | 423 |
|
@@ -449,7 +463,8 @@ We use it in our official virtualenv integration https://github.com/pypa/virtual
|
449 | 463 |
|
450 | 464 | Another example could be our unofficial Conda module: https://github.com/nushell/nu_scripts/blob/f86a060c10f132407694e9ba0f536bfe3ee51efc/modules/virtual_environments/conda.nu
|
451 | 465 |
|
452 |
| -_WIP_ |
| 466 | +> **Warning** |
| 467 | +> Work In Progress |
453 | 468 |
|
454 | 469 | ## Hiding
|
455 | 470 |
|
@@ -488,4 +503,5 @@ It can be one of the following:
|
488 | 503 |
|
489 | 504 | - Hides all of the module's exports, without the prefix
|
490 | 505 |
|
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