Skip to content

Commit 97367e8

Browse files
committed
docs: Overhaul docs
1 parent fd67bc9 commit 97367e8

File tree

11 files changed

+137
-141
lines changed

11 files changed

+137
-141
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.watcherExclude": {
3+
"**/target": true
4+
}
5+
}

docs/how-to/local-projects.md

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,89 @@
11
# Local Projects
22

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
44

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
66

77
```sh
88
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'
139
```
1410

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
1612

1713
```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
2016
```
2117

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
2319

2420
```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]
2741
```
2842

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
3044

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)
3946

40-
It now shows up in the `list` subcommand
47+
To execute this program, simply run
4148

4249
```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
5052

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
5256

53-
Create a `script.sh` file
57+
set <number>
58+
Sets the current fox count
5459

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
5762

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
6065

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+
```
6370

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
6672

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
7274

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
7480
```
7581

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
7785

7886
```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
8489
```

docs/internals/history.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ After contributing a few PR's to Basher, I decided to fork the project, calling
66

77
I essentially rewrote most of the codebase, authoring an additional ~100 tests. Some of the features at this point included
88

9-
- Support for a `bpm.toml` file (in addition to backwards-compatible `package.sh` support)
10-
- Substantiallly better help output
9+
- Support for a `bpm.toml` file (in addition to backwards-compatible support for `package.sh`)
10+
- Substantially better help output
1111
- Completion scripts
1212
- Support for installing many more repositories
1313
- Support for installing transitive dependencies
14+
- Improved support for installing different branches / versions
1415
- Over 250+ tests
1516

1617
Although the code was heavily tested, I didn't really like _how_ packages were installed. It was inefficient and had the potential for bugs. When I had this realization, I decided to essentially start from scratch again, coding the design that is implemented today. I threw out the 250+ custom tests, implementations of commands, and nearly everything with the exception of a few low-level parsing functions. Contemporaneously, I renamed the project to `basalt`, and worked on the from-scratch implementation in a branch called `wip` until it was subsequently merged into `main`

docs/internals/motivation.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
A mechanism to facilitate composability within the Bash ecosystem, á la a package manager
44

5-
The general idea isn't new; there exist two prominent package managers (`bpkg` and `Basher`) along with a slew of other highly prolific Bash/shell projects (`oh-my-zsh`, `bash-it`, `bash-oo-framework`) that aim to solve similar problems. How is Basalt different?
5+
The general idea isn't new; there are many similar projects, but Basalt fills a unique void
66

7-
1. `oh-my-zsh`, `bash-it`, and friends are more geared towards reusability (not composability) in the context of shell initialization
8-
2. `bash-oo-framework` contains a lot of useful functionality, but as the name implies, it must be used as a framework rather than a library; this doesn't mame it very composable. Furthermore, the project itself recommends directly copying and pasting code from the repository as a usage pattern, which is highly laborious and frictious
9-
3. `bpkg` and `Basher` are two projects that fit the criteria, but have some disadvantages in my opinion
7+
- It is not meant to be a replacement for `oh-my-zsh`, `bash-it`, etc. The aforementioned are used only in the context of shell initialization and are more geared towards reusability (not composability)
8+
9+
- It is unlike `bash-oo-framework` in that it facilitates the creation of _packages like_ `bash-oo-framework`. That is, cool features that are a part of `bash-oo-framework` like stack traces can be installable as a library rather than a greater framework
10+
11+
- The two existing prominent package managers (`bpkg` and `Basher`) are most similar, but fall short. Some gripes are listed below
1012

1113
### `bpkg` disadvantages
1214

@@ -28,4 +30,5 @@ The general idea isn't new; there exist two prominent package managers (`bpkg` a
2830
- Cannot install local, per-project dependencies
2931
- Have subpar completion scripts
3032

31-
These disadvantages gave me reason to create a new package manager that was significantly improved. I originally forked Basher because it had an excellent test suite and its behavior for installing packages made more sense to me. However, since a massive refactoring effort in addition to a near-complete rewrite took effect, there is almost no original Basher code that exists currently
33+
34+
For each tool, the issues were systemic so I forked Basher and made heavy modifications, eventually doing a complete rewrite

docs/internals/package-installation.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,36 @@ This page provides information on how and where packages are installed.
44

55
The installation of packages is split into four phases. Each of these phases corresponds to a function in `pkg.sh`
66

7-
1. Package download
8-
2. Package extraction
9-
3. Package global integration
10-
4. Package local integration (recursive)
11-
5. Package local integration (non-recursive)
7+
1. Package download `pkg.phase_download_tarball()`
8+
2. Package extraction `pkg.phase_extract_tarball()`
9+
3. Package global integration (recursive) `pkg.phase_local_integration_recursive() "$BASALT_GLOBAL_DATA_DIR..."`
10+
4. Package global integration (non-recursive) `pkg.phase_local_integration_nonrecursive() "$BASALT_GLOBAL_DATA_DIR..."`
11+
5. Package local integration (recursive) `pkg.phase_local_integration_recursive() "$BASALT_LOCAL_PROJECT_DIR..."`
12+
6. Package local integration (non-recursive) `pkg.phase_local_integration_nonrecursive() "$BASALT_LOCAL_PROJECT_DIR..."`
1213

1314
## 1. Package download
1415

1516
During this stage, tarballs files are downloaded from the internet to `$BASALT_GLOBAL_DATA_DIR/store/tarballs`
1617

17-
In most cases, tarballs can be downloaded directly. From the point of view of a consumer, you can access these types of tarballs by specifying a revision like `@v0.3.0'` in `dependencies`. From the point of view of a package maintainer, enable this behavior by authoring a GitHub release based on a release commit of a Git repository. Doing this is most efficient since the whole Git repository does not need to be downloaded
18+
In most cases, tarballs can be downloaded directly. From the point of view of a consumer, you can access these types of tarballs by specifying a revision like `@v0.3.0'` in `dependencies`. From the point of view of a package maintainer, enable this behavior by authoring a GitHub release based on a git tag of a Git repository. Doing this is most efficient since the whole Git repository does not need to be downloaded
1819

1920
Sometimes, a package consumer may want to use a revision that is not a release (e.g. `@e5466e6c3998790ebd99768cf0f910e161b84a95`). When this type of revision is specified, Basalt will clone the entire repository, then use `git-archive(1)` to extract the revision in the form of a tarball
2021

2122
## 2. Package extraction
2223

2324
During this stage, tarball files located in `$BASALT_GLOBAL_DATA_DIR/store/tarballs` are simply extracted and placed in `$BASALT_GLOBAL_DATA_DIR/store/packages`
2425

25-
### 3. Global integration
26+
### 3. Global integration (recursive)
2627

27-
For each package in `$BASALT_GLOBAL_DATA_DIR/store/packages`, modifications are done. This includes but is not limited to
28+
For each package in `$BASALT_GLOBAL_DATA_DIR/store/packages`, modifications are done. Find more information about the modifications in "recursive local integration"
2829

29-
- Appending version numbers to all functions
30-
- Creating a local `./.basalt` directory (local integration)
31-
- Converting the runtime essence of the `./basalt.toml` file into other files that are either sourceable or easier to parse
3230

33-
### 4. Local integration (recursive)
31+
32+
### 4. Global integration (non-recursive)
33+
34+
For each package in `$BASALT_GLOBAL_DATA_DIR/store/packages`, modifications are done that don't require recursively resolving subdependencies. Find more information about the modifications in "non-recursive local integration"
35+
36+
### 5. Local integration (recursive)
3437

3538
This step involves creating a `.basalt` directory so the functionality of all dependencies can be properly exposed. The directory is located at `$BASALT_LOCAL_PROJECT_DIR/.basalt` for local dependencies and at `$BASALT_GLOBAL_DATA_DIR/global/.basalt` for global dependencies
3639

@@ -47,6 +50,9 @@ This step involves creating a `.basalt` directory so the functionality of all de
4750
- packages/
4851
```
4952

50-
### 5. Local integration (non-recursive)
53+
### 6. Local integration (non-recursive)
5154

5255
This is similar to the previous step, except it performs functionalities that are inherently non recursive. This includes creating the `./basalt/generated` subdirectory and the files within it
56+
57+
- Appending version numbers to all functions
58+
- Converting the runtime essence of the `./basalt.toml` file into other files that are either sourceable or easier to parse

docs/reference/environment.md renamed to docs/reference/api.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Environment
22

3-
## Global Environment Variables
3+
## Global
44

55
Global environment variables are both valid globally (after `eval "$(basalt global init bash)"`) and locally (after `eval "$(basalt-package-init)"; basalt.package-init`)
66

@@ -12,10 +12,30 @@ The location of the source code. By default (when using the `install.sh` script)
1212

1313
The directory Basalt stores nearly all data. This includes downloaded tarballs, directories extracted from tarballs, and the directories that contain global installations of packages. By default, this has the value of `${XDG_DATA_HOME:-$HOME/.local/share}/basalt`
1414

15-
## Local Environment Variables
15+
### `basalt.load`
16+
17+
Sources a particular file of a particular package
18+
19+
For example, the below example sources the `z.sh` file that is present at the root of [rupa/z](https://github.com/rupa/z). Note that you must pass in the website, as well as the repository owner and repository name
20+
21+
```sh
22+
basalt.load --global 'github.com/rupa/z' 'z.sh'
23+
```
24+
25+
If you do not pass a file, it will automatically source a `load.bash` at the root of the repository, if it exists
26+
27+
## Local
1628

1729
Local environment variables are only valid within a Bash package (after `eval "$(basalt-package-init)"; basalt.package-init`)
1830

1931
### `BASALT_PACKAGE_DIR`
2032

2133
The full path to the current project. It is calculated by walking up the file tree from `$PWD`, only stopping after detecting a `./basalt.toml`. The directory that was stopped at is the new value of `BASALT_PACKAGE_DIR`
34+
35+
### `basalt.package-load`
36+
37+
Loads all Basalt dependencies
38+
39+
```sh
40+
basalt.package-load
41+
```

docs/reference/interface.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)