|
1 | 1 | # Local Projects
|
2 | 2 |
|
3 |
| -TODO: WARNING: This is out of date |
| 3 | +Similar to `cargo`, `yarn` etc., Basalt allows for the installation of packages on a per-project basis. This page details how to do it with Basalt |
4 | 4 |
|
5 |
| -Similar to `npm`, `carto`, etc. `basalt` allows for the installation of packages on a per-project basis. Use `basalt.toml` for this |
| 5 | +First, create a project directory |
6 | 6 |
|
7 | 7 | ```sh
|
8 | 8 | mkdir 'my-project' && cd 'my-project'
|
9 |
| - |
10 |
| -# Creating a 'basalt.toml' is required so basalt knows where |
11 |
| -# the root of the project is |
12 |
| -touch 'basalt.toml' |
13 | 9 | ```
|
14 | 10 |
|
15 |
| -Let's take a look at the installed packages |
| 11 | +Now, initialize a new project. We'll be passing in `--full`; if you want a more minimalist template, pass `--bare` instead |
16 | 12 |
|
17 | 13 | ```sh
|
18 |
| -$ basalt list |
19 |
| -Info: Operating in context of local basalt.toml |
| 14 | +$ basalt init --full |
| 15 | + Info Cloned github.com/hyperupcall/template-bash |
20 | 16 | ```
|
21 | 17 |
|
22 |
| -So far, none are installed. Let's install [bash-args](https://github.com/hyperupcall/bash-args). To do this, modify `dependencies` in your `basalt.toml` |
| 18 | +Naturally, the most important part of Basalt packages is the `basalt.toml` file |
23 | 19 |
|
24 | 20 | ```toml
|
25 |
| -# basalt.toml |
26 |
| -dependencies = [ "hyperupcall/bash-args" ] |
| 21 | +[package] |
| 22 | +name = 'fox-track' |
| 23 | +slug = 'fox_track' |
| 24 | +version = '0.1.0' |
| 25 | +authors = ['Edwin Kofler <edwin@kofler.dev>'] |
| 26 | +description = 'A template to get started writing Bash applications and projects' |
| 27 | + |
| 28 | +[run] |
| 29 | +dependencies = ['https://github.com/hyperupcall/bats-common-utils.git@v3.0.0'] |
| 30 | +sourceDirs = ['pkg/lib/public', 'pkg/lib'] |
| 31 | +builtinDirs = [] |
| 32 | +binDirs = ['pkg/bin'] |
| 33 | +completionDirs = ['completions'] |
| 34 | +manDirs = [] |
| 35 | + |
| 36 | +[run.shellEnvironment] |
| 37 | + |
| 38 | +[run.setOptions] |
| 39 | + |
| 40 | +[run.shoptOptions] |
27 | 41 | ```
|
28 | 42 |
|
29 |
| -Now, install it |
| 43 | +In short, `name` is the pretty name for the package. Often, it has the same name as the repository. `slug` is the string used to prefix *all of* your functions when you want your package to be consumed as a library. Lastly, `sourceDirs` are all the directories containing shell files you wish to source. Note that `pkg/lib/cmd` is *not* added since it contains files that are entrypoints for new Bash processes |
30 | 44 |
|
31 |
| -```sh |
32 |
| -$ basalt add --all |
33 |
| -Info: Operating in context of local basalt.toml |
34 |
| -Info: Adding all dependencies |
35 |
| -Info: Adding 'hyperupcall/bash-args' |
36 |
| - -> Cloning Git repository |
37 |
| - -> Symlinking bin files |
38 |
| -``` |
| 45 | +A detailed description for each key can be found at [`reference/basalt_toml`](./docs/reference/basalt_toml.md) |
39 | 46 |
|
40 |
| -It now shows up in the `list` subcommand |
| 47 | +To execute this program, simply run |
41 | 48 |
|
42 | 49 | ```sh
|
43 |
| -$ basalt list |
44 |
| -Info: Operating in context of local basalt.toml |
45 |
| -github.com/hyperupcall/bash-args |
46 |
| - Branch: main |
47 |
| - Revision: 2087e87 |
48 |
| - State: Up to date |
49 |
| -``` |
| 50 | +$ basalt run fox-track --help |
| 51 | +fox-track: A fox tracking sample application |
50 | 52 |
|
51 |
| -You'll notice a `.basalt` directory has been created. Since the project is now installed, let's use it |
| 53 | +Commands: |
| 54 | + show |
| 55 | + Shows the current fox count |
52 | 56 |
|
53 |
| -Create a `script.sh` file |
| 57 | + set <number> |
| 58 | + Sets the current fox count |
54 | 59 |
|
55 |
| -```sh |
56 |
| -#!/usr/bin/env bash |
| 60 | + add [number] |
| 61 | + Adds a number to the current fox count. If number is not specified, it defaults to 1 |
57 | 62 |
|
58 |
| -# @file script.sh |
59 |
| -# @brief Demonstration of the bash-args library |
| 63 | + remove [number] |
| 64 | + Adds a number to the current fox count. If number is not specified, it defaults to 1 |
60 | 65 |
|
61 |
| -# Append to the PATH so we have access to `bash-args` in the PATH |
62 |
| -PATH="$PWD/.basalt/bin:$PATH" |
| 66 | +Flags: |
| 67 | + --help |
| 68 | + Shows the help menu |
| 69 | +``` |
63 | 70 |
|
64 |
| -# Declare an associative array for storing the argument flags |
65 |
| -declare -A args=() |
| 71 | +This is similar to running `./pkg/bin/fox-track` directly, but using `basalt run` has another benefit: Basalt will look for commands of the specified name not just for the current project, but for all subdependencies as well |
66 | 72 |
|
67 |
| -# 'bash-args' requires that we use `source`, so it can |
68 |
| -# set fields in the 'args' associative array |
69 |
| -source bash-args parse "$@" <<-"EOF" |
70 |
| -@flag [port.p] {3000} - The port to open on |
71 |
| -EOF |
| 73 | +If you wish to add a dependency to the project, use the `add` subcommand |
72 | 74 |
|
73 |
| -printf '%s\n' "Using port '${args[port]}'" |
| 75 | +```sh |
| 76 | +$ basalt add 'hyperupcall/bats-common-utils' |
| 77 | + Downloaded github.com/hyperupcall/bats-common-utils@v3.0.0 |
| 78 | + Extracted github.com/hyperupcall/bats-common-utils@v3.0.0 |
| 79 | +Transformed github.com/hyperupcall/bats-common-utils@v3.0.0 |
74 | 80 | ```
|
75 | 81 |
|
76 |
| -Cool, now let's try it |
| 82 | +Basalt will automatically find and download the version corresponding to the _latest GitHub release_. If there are no GitHub releases, it will use the latest commit. In this case, `v3.0.0` was the latest GitHub release |
| 83 | + |
| 84 | +You can view the dependencies by looking in `basalt.toml` or running |
77 | 85 |
|
78 | 86 | ```sh
|
79 |
| -$ chmod +x './script.sh' |
80 |
| -$ ./script.sh |
81 |
| -Using port '3000' |
82 |
| -$ ./script.sh --port 4000 |
83 |
| -Using port '4000' |
| 87 | +$ basalt list |
| 88 | +https://github.com/hyperupcall/bats-common-utils.git@v3.0.0 |
84 | 89 | ```
|
0 commit comments