Skip to content

Commit 2864a42

Browse files
committed
chore: added list command and updated docs
1 parent 7276579 commit 2864a42

File tree

7 files changed

+114
-27
lines changed

7 files changed

+114
-27
lines changed

docs/cli/index.md

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,13 @@
9090
- [--workspace, --no-workspace](#--workspace---no-workspace)
9191
- [-a, --answer ](#-a---answer--)
9292
- [example](#example)
93+
- [Options](#options-13)
94+
- [-l, --list](#-l---list)
9395
- [Arguments](#arguments-9)
9496
- [EXAMPLE_ID](#example_id)
9597
- [localnet](#localnet)
9698
- [codespace](#codespace)
97-
- [Options](#options-13)
99+
- [Options](#options-14)
98100
- [-m, --machine ](#-m---machine-)
99101
- [-a, --algod-port ](#-a---algod-port-)
100102
- [-i, --indexer-port ](#-i---indexer-port-)
@@ -104,22 +106,22 @@
104106
- [-t, --timeout ](#-t---timeout-)
105107
- [-f, --force](#-f---force-1)
106108
- [config](#config-1)
107-
- [Options](#options-14)
109+
- [Options](#options-15)
108110
- [-f, --force](#-f---force-2)
109111
- [Arguments](#arguments-10)
110112
- [ENGINE](#engine-1)
111113
- [console](#console)
112114
- [explore](#explore-1)
113115
- [logs](#logs)
114-
- [Options](#options-15)
116+
- [Options](#options-16)
115117
- [--follow, -f](#--follow--f)
116118
- [--tail ](#--tail-)
117119
- [reset](#reset)
118-
- [Options](#options-16)
120+
- [Options](#options-17)
119121
- [--update, --no-update](#--update---no-update)
120122
- [-P, --config-dir ](#-p---config-dir-)
121123
- [start](#start)
122-
- [Options](#options-17)
124+
- [Options](#options-18)
123125
- [-n, --name ](#-n---name--1)
124126
- [-P, --config-dir ](#-p---config-dir--1)
125127
- [-d, --dev, --no-dev](#-d---dev---no-dev)
@@ -128,18 +130,18 @@
128130
- [stop](#stop)
129131
- [project](#project)
130132
- [bootstrap](#bootstrap)
131-
- [Options](#options-18)
132-
- [--force](#--force-1)
133133
- [Options](#options-19)
134+
- [--force](#--force-1)
135+
- [Options](#options-20)
134136
- [--interactive, --no-ci, --non-interactive, --ci](#--interactive---no-ci---non-interactive---ci)
135137
- [-p, --project-name ](#-p---project-name-)
136138
- [-t, --type ](#-t---type-)
137-
- [Options](#options-20)
138-
- [--interactive, --non-interactive, --ci](#--interactive---non-interactive---ci)
139139
- [Options](#options-21)
140+
- [--interactive, --non-interactive, --ci](#--interactive---non-interactive---ci)
141+
- [Options](#options-22)
140142
- [--ci, --no-ci](#--ci---no-ci)
141143
- [deploy](#deploy)
142-
- [Options](#options-22)
144+
- [Options](#options-23)
143145
- [-C, -c, --command ](#-c--c---command-)
144146
- [--interactive, --non-interactive, --ci](#--interactive---non-interactive---ci-1)
145147
- [-P, --path ](#-p---path-)
@@ -150,7 +152,7 @@
150152
- [ENVIRONMENT_NAME](#environment_name)
151153
- [EXTRA_ARGS](#extra_args)
152154
- [link](#link)
153-
- [Options](#options-23)
155+
- [Options](#options-24)
154156
- [-p, --project-name ](#-p---project-name--2)
155157
- [-l, --language ](#-l---language--1)
156158
- [-a, --all](#-a---all)
@@ -162,7 +164,7 @@
162164
- [run](#run)
163165
- [task](#task)
164166
- [analyze](#analyze)
165-
- [Options](#options-24)
167+
- [Options](#options-25)
166168
- [-r, --recursive](#-r---recursive)
167169
- [--force](#--force-2)
168170
- [--diff](#--diff)
@@ -171,11 +173,11 @@
171173
- [Arguments](#arguments-13)
172174
- [INPUT_PATHS](#input_paths)
173175
- [ipfs](#ipfs)
174-
- [Options](#options-25)
176+
- [Options](#options-26)
175177
- [-f, --file ](#-f---file--1)
176178
- [-n, --name ](#-n---name--2)
177179
- [mint](#mint)
178-
- [Options](#options-26)
180+
- [Options](#options-27)
179181
- [--creator ](#--creator-)
180182
- [--name ](#--name-)
181183
- [-u, --unit ](#-u---unit-)
@@ -187,45 +189,45 @@
187189
- [--mutable, --immutable](#--mutable---immutable)
188190
- [-n, --network ](#-n---network-)
189191
- [nfd-lookup](#nfd-lookup)
190-
- [Options](#options-27)
192+
- [Options](#options-28)
191193
- [-o, --output ](#-o---output--3)
192194
- [Arguments](#arguments-14)
193195
- [VALUE](#value)
194196
- [opt-in](#opt-in)
195-
- [Options](#options-28)
197+
- [Options](#options-29)
196198
- [-a, --account ](#-a---account-)
197199
- [-n, --network ](#-n---network--1)
198200
- [Arguments](#arguments-15)
199201
- [ASSET_IDS](#asset_ids)
200202
- [opt-out](#opt-out)
201-
- [Options](#options-29)
203+
- [Options](#options-30)
202204
- [-a, --account ](#-a---account--1)
203205
- [--all](#--all)
204206
- [-n, --network ](#-n---network--2)
205207
- [Arguments](#arguments-16)
206208
- [ASSET_IDS](#asset_ids-1)
207209
- [send](#send)
208-
- [Options](#options-30)
210+
- [Options](#options-31)
209211
- [-f, --file ](#-f---file--2)
210212
- [-t, --transaction ](#-t---transaction-)
211213
- [-n, --network ](#-n---network--3)
212214
- [sign](#sign)
213-
- [Options](#options-31)
215+
- [Options](#options-32)
214216
- [-a, --account ](#-a---account--2)
215217
- [-f, --file ](#-f---file--3)
216218
- [-t, --transaction ](#-t---transaction--1)
217219
- [-o, --output ](#-o---output--4)
218220
- [--force](#--force-3)
219221
- [transfer](#transfer)
220-
- [Options](#options-32)
222+
- [Options](#options-33)
221223
- [-s, --sender ](#-s---sender-)
222224
- [-r, --receiver ](#-r---receiver--1)
223225
- [--asset, --id ](#--asset---id-)
224226
- [-a, --amount ](#-a---amount--1)
225227
- [--whole-units](#--whole-units-2)
226228
- [-n, --network ](#-n---network--4)
227229
- [vanity-address](#vanity-address)
228-
- [Options](#options-33)
230+
- [Options](#options-34)
229231
- [-m, --match ](#-m---match-)
230232
- [-o, --output ](#-o---output--5)
231233
- [-a, --alias ](#-a---alias-)
@@ -234,19 +236,19 @@
234236
- [Arguments](#arguments-17)
235237
- [KEYWORD](#keyword)
236238
- [wallet](#wallet)
237-
- [Options](#options-34)
239+
- [Options](#options-35)
238240
- [-a, --address ](#-a---address-)
239241
- [-m, --mnemonic](#-m---mnemonic)
240242
- [-f, --force](#-f---force-4)
241243
- [Arguments](#arguments-18)
242244
- [ALIAS_NAME](#alias_name)
243245
- [Arguments](#arguments-19)
244246
- [ALIAS](#alias)
245-
- [Options](#options-35)
247+
- [Options](#options-36)
246248
- [-f, --force](#-f---force-5)
247249
- [Arguments](#arguments-20)
248250
- [ALIAS](#alias-1)
249-
- [Options](#options-36)
251+
- [Options](#options-37)
250252
- [-f, --force](#-f---force-6)
251253

252254
# algokit
@@ -729,6 +731,12 @@ The example will be copied to a new directory in your current location.
729731
algokit init example [OPTIONS] [EXAMPLE_ID]
730732
```
731733

734+
### Options
735+
736+
737+
### -l, --list
738+
List all available examples
739+
732740
### Arguments
733741

734742

docs/features/init.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,42 @@ As a suggestion, if you wanted to open the project in VS Code you could execute:
119119
120120
```
121121

122+
## Initializing Examples
123+
124+
AlgoKit provides a collection of pre-built example projects that you can use to quickly start development. These examples demonstrate various use cases and best practices for Algorand development.
125+
126+
### Using the Example Command
127+
128+
You can initialize a new project from an example using the `algokit init example` command:
129+
130+
```bash
131+
# List and select from available examples interactively
132+
algokit init example
133+
134+
#List the available examples
135+
algokit init example -l/--list
136+
137+
# Initialize a specific example directly
138+
algokit init example <example_id>
139+
```
140+
141+
When run without an example ID, the command launches an interactive selector that displays available examples with their descriptions and categories. Examples are copied to a new directory in your current location, named after the example ID.
142+
143+
### Available Examples
144+
145+
Examples are organized in the AlgoKit templates repository and cover various use cases including:
146+
147+
- Smart contract examples
148+
- dApp frontend examples
149+
- Full-stack applications
150+
- Integration samples
151+
152+
Each example comes with all necessary files and configurations to get started immediately. After initialization, you can navigate to the example directory and begin development.
153+
154+
### Exploring Example Code
155+
156+
To explore what examples are available before initializing, you can run the interactive selector and browse through the options. Examples include a name and type to help you select the most appropriate one for your needs.
157+
158+
After initializing an example, AlgoKit automatically attempts to open the project in your default IDE to help you quickly start exploring and modifying the code.
159+
122160
For more details about the `AlgoKit init` command, please refer to the [AlgoKit CLI reference documentation](../cli/index.md#init).

src/algokit/cli/init/example.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
@click.command("example")
1717
@click.argument("example_id", required=False)
18-
def example_command(example_id: str) -> None:
18+
@click.option("-l", "--list", "list_examples", is_flag=True, help="List all available examples")
19+
def example_command(example_id: str, *, list_examples: bool) -> None:
1920
"""Initialize a new project from an example template.
2021
2122
Allows you to quickly create a new project by copying one of the official AlgoKit example templates.
@@ -24,14 +25,22 @@ def example_command(example_id: str) -> None:
2425

2526
_manage_templates_repository()
2627

28+
examples_config_path = Path.home() / ALGOKIT_USER_DIR / ALGOKIT_TEMPLATES_DIR / "examples" / "examples.yml"
29+
30+
if list_examples:
31+
examples = _load_algokit_examples(str(examples_config_path.absolute()))
32+
click.echo("Available examples:")
33+
for example in examples:
34+
click.echo(f" {example['id']} - {example.get('name', '')}")
35+
return
36+
2737
if not example_id:
2838
app = ExampleSelector()
2939
app.run()
3040
example_id = app.user_answers.get("example_id", "")
3141
if not example_id:
3242
return
3343

34-
examples_config_path = Path.home() / ALGOKIT_USER_DIR / ALGOKIT_TEMPLATES_DIR / "examples" / "examples.yml"
3544
source_dir = Path.home() / ALGOKIT_USER_DIR / ALGOKIT_TEMPLATES_DIR / "examples" / example_id
3645
target_dir = Path.cwd() / example_id
3746

src/algokit/core/init.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ def _open_ide(project_path: Path, readme_path: Path | None = None, *, open_ide:
204204
logger.info(f"Your template includes a {readme_path.name} file, you might want to review that as a next step.")
205205

206206

207-
208207
def _load_algokit_examples(examples_config_path: str) -> list[dict]:
209208
"""
210209
Load and parse the examples from a YAML configuration file.

tests/init/example/test_example.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,32 @@ def test_example_command_tui_select_valid_but_source_missing(mocker: MockerFixtu
259259
mock_copytree.assert_not_called()
260260
mock_open_ide.assert_not_called()
261261
verify(result.output)
262+
263+
264+
def test_example_command_list_option(mocker: MockerFixture, cwd: Path) -> None:
265+
"""Test that the --list option displays all available examples."""
266+
267+
mock_copytree = mocker.patch("algokit.cli.init.example.shutil.copytree")
268+
mock_open_ide = mocker.patch("algokit.cli.init.example._open_ide")
269+
270+
# Test with short flag
271+
result = invoke(["init", "example", "-l"], cwd=cwd)
272+
273+
assert result.exit_code == 0
274+
assert "Available examples:" in result.output
275+
for example in MOCK_EXAMPLES:
276+
assert f" {example['id']} - {example.get('name', '')}" in result.output
277+
mock_copytree.assert_not_called()
278+
mock_open_ide.assert_not_called()
279+
verify(result.output)
280+
281+
# Test with long flag
282+
result = invoke(["init", "example", "--list"], cwd=cwd)
283+
284+
assert result.exit_code == 0
285+
assert "Available examples:" in result.output
286+
for example in MOCK_EXAMPLES:
287+
assert f" {example['id']} - {example.get('name', '')}" in result.output
288+
mock_copytree.assert_not_called()
289+
mock_open_ide.assert_not_called()
290+
verify(result.output)

tests/init/example/test_example.test_example_command_help.approved.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ Usage: algokit init example [OPTIONS] [EXAMPLE_ID]
88
copied to a new directory in your current location.
99

1010
Options:
11+
-l, --list List all available examples
1112
-h, --help Show this message and exit.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Available examples:
2+
react-vite - React Vite
3+
python-smart-contract - Python Smart Contract

0 commit comments

Comments
 (0)