Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 102 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,108 @@
# crane 🏗️
<div align="center">
<h1>crane 🏗️</h1>

Easily add bricks (files or snippets) to your projects.
Create, use and share easily reusable bootstrap packages called bricks.
<br>
<br>
<sup>
⭐ Consider starring this repo – your support motivates me a lot! ⭐
</sup>
<div>
<a href="https://crates.io/crates/crane">
<img alt="Crates.io Version" src="https://img.shields.io/crates/v/crane">
</a>
<a href="https://crates.io/crates/crane">
<img alt="Crates.io Total Downloads" src="https://img.shields.io/crates/d/crane">
</a>
<a href="https://github.com/timothebot/crane/">
<img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/timothebot/crane">
</a>
</div>
<br>
<a href="https://crane.tiimo.space/setup">Setup</a>
&nbsp;~&nbsp;
<a href="https://crane.tiimo.space/faq">FAQ</a>
&nbsp;~&nbsp;
<a href="https://crane.tiimo.space/">Documentation</a>
</div>

🧱 A brick is an instruction. It can be a file that gets added, a command that


<br>

Crane is a CLI tool that allows you to create *bricks* that you can later add to any project.

A brick is an instruction. It can be a file that gets added, a command that
executes or lines getting replaced in a target file.

> 🚧 crane is currently being worked on :D
> Some features that are already documented don't work yet
> and everything could change until a stable release!
## Examples

### License brick

Instead of having to look up and copy your desired license from the web, you can create a brick out of it and then run `crane add some-license`.

### Language specific bricks

You can create multiple bricks and combine them behind an alias.

This way, you can easily bootstrap new projects!

```shell
$ cargo new my_project && cd my_project
# ...
$ crane add rust
→ Executing 4 bricks
• mit
• serde
• rustfmt
• rustauthor
# ...
```

## Getting Started

Install the CLI using cargo (more options coming soon!)

```shell
cargo install crane
```

and set up shell completions (not required):

<details>
<summary>ZSH</summary>

```shell
# ~/.zshrc
eval "$(crane completion zsh)"
```

</details>

<details>
<summary>Bash</summary>

```shell
# ~/.bashrc
eval "$(crane completion bash)"
```

</details>

<details>
<summary>Fish</summary>

```shell
# ~/.config/fish/config.fish
crane completion fish | source
```

</details>

## Issues & Contributions

Feel free to open an issue or a PR. Help is always appreciated!

## ToDo
---

- [ ] Regex support
- [ ] Path support
- [ ] Improve readme
- [ ] Variables support
- [ ] Input variables (ask for variable or command or something)
made with <3 by [timothebot](https://github.com/timothebot)
2 changes: 2 additions & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Summary

- [Introduction](./intro.md)
- [Set Up](./setup.md)
- [Frequently Asked Questions](./faq.md)

# User Guide

Expand Down
3 changes: 3 additions & 0 deletions book/src/faq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Frequently Asked Questions

Feel free to open an issue with any questions. Common questions will then be added here!
32 changes: 32 additions & 0 deletions book/src/setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Setup

Install the CLI using cargo (more options coming soon!)

```shell
cargo install crane
```

## Shell Completions (optional)

Set up shell completions:

### ZSH

```shell
# ~/.zshrc
eval "$(crane completion zsh)"
```

### Bash

```shell
# ~/.bashrc
eval "$(crane completion bash)"
```

### Fish

```shell
# ~/.config/fish/config.fish
crane completion fish | source
```
10 changes: 7 additions & 3 deletions crane/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "crane"
description = "Easily add bricks (files or snippets) to your projects!"
version = "0.2.0"
version = "0.3.0"
edition = "2024"
license = "MIT"
readme = "../README.md"
Expand All @@ -13,11 +13,15 @@ keywords = ["cli", "tool", "utility"]
serde = { version = "1.0", features = ["derive"] }
toml = "0.9.6"
clap = { version = "4.5.47", features = ["derive"] }
clap-verbosity = "2.1.0"
fuzzy-matcher = "0.3.7"
anyhow = "1.0.99"
clap-verbosity = "2.1.0"
env_logger = "0.11.8"
log = "0.4.28"
crane_bricks = { path = "../crane_bricks/", version = "0.1.0"}
crane_bricks = { path = "../crane_bricks/", version = "0.2.0" }
colog = "1.4.0"
colored = "3.0.0"

[profile.release]
codegen-units = 1
lto = true
12 changes: 12 additions & 0 deletions crane/src/cmd/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::path::PathBuf;
use clap::{Parser, Subcommand, ValueHint};
use clap_verbosity::{InfoLevel, Verbosity};

use crate::shell::Shell;

#[derive(Debug, Parser)]
#[command(version, about, long_about = None)]
pub struct CraneCli {
Expand All @@ -17,6 +19,7 @@ pub struct CraneCli {
pub enum CraneCommand {
Add(Add),
List(List),
Completion(Completion),
}

/// Add a brick to your directory
Expand All @@ -35,9 +38,18 @@ pub struct Add {
pub dry_run: bool,
}

#[derive(Debug, Parser)]
pub struct Completion {
#[clap(required = true)]
pub shell: Shell,
}

/// List all available bricks
#[derive(Debug, Parser, Clone)]
pub struct List {
#[arg(short, long, value_hint=ValueHint::DirPath, value_terminator=",")]
pub brick_dirs: Option<Vec<PathBuf>>,

#[arg(long)]
pub no_format: bool,
}
7 changes: 7 additions & 0 deletions crane/src/cmd/completion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::cmd::{Completion, Run};

impl Run for Completion {
fn run(&self) {
println!("{}", self.shell);
}
}
12 changes: 12 additions & 0 deletions crane/src/cmd/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ impl Run for List {
&config.brick_dirs().to_vec()
};

if self.no_format {
for brick_dir in brick_dirs {
for brick in bricks_in_dir(brick_dir) {
println!("{}", brick.name());
}
}
for alias in config.alias() {
println!("{}", alias.name());
}
return;
}

let alias_mapped = map_aliases(config.alias());

for brick_dir in brick_dirs {
Expand Down
2 changes: 2 additions & 0 deletions crane/src/cmd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod add;
mod commands;
mod completion;
mod list;

pub use crate::cmd::commands::*;
Expand All @@ -13,6 +14,7 @@ impl Run for CraneCli {
match &self.command {
CraneCommand::Add(cmd) => cmd.run(),
CraneCommand::List(cmd) => cmd.run(),
CraneCommand::Completion(cmd) => cmd.run(),
}
}
}
1 change: 1 addition & 0 deletions crane/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::cmd::{CraneCli, Run};
mod cmd;
mod config;
mod logging;
mod shell;

fn main() {
let cli = CraneCli::parse();
Expand Down
72 changes: 72 additions & 0 deletions crane/src/shell.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use std::fmt::Display;

use clap::ValueEnum;

#[derive(ValueEnum, Debug, Clone, Copy)]
pub enum Shell {
Bash,
Zsh,
Fish,
}

impl Display for Shell {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(
f,
"{}",
match self {
Shell::Bash =>
r#"
# START generated crane shell config
_crane() {
local cur
cur="${COMP_WORDS[COMP_CWORD]}"
local subcommands="list add completions"
if [[ $COMP_CWORD -eq 1 ]]; then
COMPREPLY=( $(compgen -W "$subcommands" -- "$cur") )
return
fi
if [[ ${COMP_WORDS[1]} == add ]]; then
local items
items="$(crane list --no-format 2>/dev/null)"
COMPREPLY=( $(compgen -W "$items" -- "$cur") )
return
fi
}
complete -F _crane crane
# END generated crane shell config"#,
Shell::Zsh =>
r#"
# START generated crane shell config
_crane() {
local -a subcmds add_args
subcmds=(
'add:Add bricks'
'list:List bricks'
'completions:Generate shell completions'
)
if (( CURRENT == 2 )); then
_describe 'subcommand' subcmds
return
fi
case $words[2] in
add)
_arguments "*:argument:($(crane list --no-format))"
;;
esac
}
compdef _crane crane
# END generated crane shell config"#,
Shell::Fish =>
r#"
# START generated crane shell config
complete -c crane -f -n '__fish_use_subcommand' -a list -d 'List bricks'
complete -c crane -f -n '__fish_use_subcommand' -a add -d 'Add bricks'
complete -c crane -f -n '__fish_use_subcommand' -a completions -d 'Generate shell completions'
complete -c crane -f -n '__fish_seen_subcommand_from add' \
-a '(crane list --no-format 2>/dev/null)'
# END generated crane shell config"#,
}
)
}
}
2 changes: 1 addition & 1 deletion crane_bricks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "crane_bricks"
description = "Execute bricks"
version = "0.1.0"
version = "0.2.0"
edition = "2024"
license = "MIT"
repository = "https://github.com/timothebot/crane"
Expand Down