Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devshells: full add vhs #78

Closed
wants to merge 7 commits into from
Closed
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.

40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ Usage: flake-edit [OPTIONS] [FLAKE_REF] <COMMAND>
Commands:
add
Add a new flake reference
change

remove
Remove a specific flake reference based on its id
list
List flake inputs
update
Update inputs to their latest specified release
pin
Pin inputs to their current or a specified rev
help
Print this message or the help of the given subcommand(s)

Expand Down Expand Up @@ -95,6 +95,21 @@ Options:
```
![flake-edit remove example](https://vhs.charm.sh/vhs-1Uo70AaoEMuYh2UR1JVARD.gif)

### `$ flake-edit update`
`$ flake-edit help update`

```
Update inputs to their latest specified release

Usage: flake-edit update

Options:
-h, --help
Print help
```

![flake-edit update example](https://vhs.charm.sh/vhs-V3ryrOu4Sd1ZU1KmvULCN.gif)

### `$ flake-edit list`
`$ flake-edit help list`

Expand All @@ -114,6 +129,27 @@ List the outputs, that are specified inside the inputs attribute.
List the outputs, that are specified inside the inputs attribute, in json format.
![flake-edit list example](https://vhs.charm.sh/vhs-35E6eiL63lFTSC70rQyE1Y.gif)

### `$ flake-edit pin`
`$ flake-edit help pin`

```
Pin inputs to their current or a specified rev

Usage: flake-edit pin <ID> [REV]

Arguments:
<ID>
The id of an input attribute
[REV]
Optionally specify a rev for the inputs attribute

Options:
-h, --help
Print help
```
![flake-edit pin](https://vhs.charm.sh/vhs-629lX7LqP4MS1aHffb4Ufh.gif)
Pin a specific input to it's current revision (rev).


## License
MIT
12 changes: 8 additions & 4 deletions assets/completions/fish/completions.fish
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ function __fish_complete_inputs
flake-edit list --format simple 2>/dev/null
end

function __fish_complete_inputs_toplevel
flake-edit list --format toplevel 2>/dev/null
end

function __fish_complete_add
flake-edit completion add 2>/dev/null
end
Expand All @@ -10,10 +14,10 @@ complete -c flake-edit -n "__fish_seen_subcommand_from rm" -f -a "(__fish_comple
complete -c flake-edit -n "__fish_seen_subcommand_from remove" -f -a "(__fish_complete_inputs)" -d Input
complete -c flake-edit -n "__fish_seen_subcommand_from change" -f -a "(__fish_complete_inputs)" -d Input
complete -c flake-edit -n "__fish_seen_subcommand_from c" -f -a "(__fish_complete_inputs)" -d Input
complete -c flake-edit -n "__fish_seen_subcommand_from pin" -f -a "(__fish_complete_inputs)" -d Input
complete -c flake-edit -n "__fish_seen_subcommand_from p" -f -a "(__fish_complete_inputs)" -d Input
complete -c flake-edit -n "__fish_seen_subcommand_from pin" -f -a "(__fish_complete_inputs_toplevel)" -d Input
complete -c flake-edit -n "__fish_seen_subcommand_from p" -f -a "(__fish_complete_inputs_toplevel)" -d Input

set -x ignore_space true
complete -c flake-edit -n "__fish_seen_subcommand_from a" -f -r --keep-order -a "(__fish_complete_add)" -d Add
complete -c flake-edit -n "__fish_seen_subcommand_from add" -f -r --keep-order -a "(__fish_complete_add)" -d Add
complete -c flake-edit -n "__fish_seen_subcommand_from a" -f -r --keep-order -a "(__fish_complete_add)" -d Add
complete -c flake-edit -n "__fish_seen_subcommand_from add" -f -r --keep-order -a "(__fish_complete_add)" -d Add
set -x ignore_space false
71 changes: 71 additions & 0 deletions assets/tape/pin_input.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# VHS documentation
#
# Output:
# Output <path>.gif Create a GIF output at the given <path>
# Output <path>.mp4 Create an MP4 output at the given <path>
# Output <path>.webm Create a WebM output at the given <path>
#
# Require:
# Require <string> Ensure a program is on the $PATH to proceed
#
# Settings:
# Set FontSize <number> Set the font size of the terminal
# Set FontFamily <string> Set the font family of the terminal
# Set Height <number> Set the height of the terminal
# Set Width <number> Set the width of the terminal
# Set LetterSpacing <float> Set the font letter spacing (tracking)
# Set LineHeight <float> Set the font line height
# Set LoopOffset <float>% Set the starting frame offset for the GIF loop
# Set Theme <json|string> Set the theme of the terminal
# Set Padding <number> Set the padding of the terminal
# Set Framerate <number> Set the framerate of the recording
# Set PlaybackSpeed <float> Set the playback speed of the recording
# Set MarginFill <file|#000000> Set the file or color the margin will be filled with.
# Set Margin <number> Set the size of the margin. Has no effect if MarginFill isn't set.
# Set BorderRadius <number> Set terminal border radius, in pixels.
# Set WindowBar <string> Set window bar type. (one of: Rings, RingsRight, Colorful, ColorfulRight)
# Set WindowBarSize <number> Set window bar size, in pixels. Default is 40.
# Set TypingSpeed <time> Set the typing speed of the terminal. Default is 50ms.
#
# Sleep:
# Sleep <time> Sleep for a set amount of <time> in seconds
#
# Type:
# Type[@<time>] "<characters>" Type <characters> into the terminal with a
# <time> delay between each character
#
# Keys:
# Backspace[@<time>] [number] Press the Backspace key
# Down[@<time>] [number] Press the Down key
# Enter[@<time>] [number] Press the Enter key
# Space[@<time>] [number] Press the Space key
# Tab[@<time>] [number] Press the Tab key
# Left[@<time>] [number] Press the Left Arrow key
# Right[@<time>] [number] Press the Right Arrow key
# Up[@<time>] [number] Press the Up Arrow key
# Down[@<time>] [number] Press the Down Arrow key
# PageUp[@<time>] [number] Press the Page Up key
# PageDown[@<time>] [number] Press the Page Down key
# Ctrl+<key> Press the Control key + <key> (e.g. Ctrl+C)
#
# Display:
# Hide Hide the subsequent commands from the output
# Show Show the subsequent commands in the output

Output output/pin_input.gif

Require echo

Set Shell "fish"
Set FontSize 32
Set Width 1200
Set Height 600

Hide
#Type "echo 'Welcome to VHS!'" Sleep 500ms Enter
Type "set -x fish_function_path ''" Enter
Type "clear" Enter
Show

Type "flake-edit --diff pin rust-overlay" Sleep 1000ms Enter
Sleep 5s
4 changes: 2 additions & 2 deletions assets/tape/update_input.tape
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
# Hide Hide the subsequent commands from the output
# Show Show the subsequent commands in the output

Output output/remove_input.gif
Output output/update_input.gif

Require echo

Expand All @@ -67,5 +67,5 @@ Type "set -x fish_function_path ''" Enter
Type "clear" Enter
Show

Type "fe --diff update" Sleep 1000ms Enter
Type "flake-edit --diff update" Sleep 1000ms Enter
Sleep 5s
2 changes: 1 addition & 1 deletion nix/devshells.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ _: {
};
full = pkgs.mkShellNoCC {
inputsFrom = [
self'.packages.default
self'.devShells.default
];
packages = [
pkgs.cargo-deny
pkgs.cargo-mutants
pkgs.cargo-tarpaulin
pkgs.vhs
];
};
};
Expand Down
17 changes: 11 additions & 6 deletions src/bin/flake-edit/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ impl CliArgs {
pub(crate) fn update(&self) -> bool {
matches!(self.subcommand, Command::Update { .. })
}
pub(crate) fn pin(&self) -> bool {
matches!(self.subcommand, Command::Pin { .. })
}

pub fn flake(&self) -> Option<&String> {
self.flake.as_ref()
Expand Down Expand Up @@ -81,12 +84,6 @@ pub(crate) enum Command {
#[arg(long, short)]
no_flake: bool,
},
// /// Change a specific flake reference based on its id.
#[command(alias = "c", arg_required_else_help = true)]
Change {
id: Option<String>,
uri: Option<String>,
},
/// Remove a specific flake reference based on its id.
#[clap(alias = "rm")]
Remove { id: Option<String> },
Expand All @@ -99,6 +96,14 @@ pub(crate) enum Command {
/// Update inputs to their latest specified release.
#[clap(alias = "u")]
Update {},
/// Pin inputs to their current or a specified rev.
#[clap(alias = "p")]
Pin {
/// The id of an input attribute.
id: String,
/// Optionally specify a rev for the inputs attribute.
rev: Option<String>,
},
#[clap(hide = true)]
#[command(name = "completion")]
/// Meant for shell completions.
Expand Down
48 changes: 35 additions & 13 deletions src/bin/flake-edit/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use flake_edit::change::Change;
use flake_edit::diff::Diff;
use flake_edit::edit;
use flake_edit::input::Follows;
use flake_edit::lock::FlakeLock;
use flake_edit::update::Updater;
use nix_uri::urls::UrlWrapper;
use nix_uri::{FlakeRef, NixUriResult};
Expand Down Expand Up @@ -92,17 +93,6 @@ fn main() -> eyre::Result<()> {
};
}
}
cli::Command::Update { .. } => {}
cli::Command::List { .. } => {}
cli::Command::Change { id, uri } => {
if let Some(id) = id {
change = Change::Change {
id: id.to_owned().into(),
ref_or_rev: None,
uri: uri.clone(),
};
}
}
cli::Command::Completion { inputs: _, mode } => match mode {
cli::CompletionMode::None => todo!(),
cli::CompletionMode::Add => {
Expand All @@ -117,6 +107,7 @@ fn main() -> eyre::Result<()> {
std::process::exit(0);
}
},
Command::Pin { .. } | Command::Update { .. } | Command::List { .. } => {}
}

if let Ok(Some(resulting_change)) = editor.apply_change(change.clone()) {
Expand Down Expand Up @@ -153,7 +144,7 @@ fn main() -> eyre::Result<()> {
} else if args.apply() {
app.root.apply(&resulting_change)?;
}
} else if !args.list() && !args.update() {
} else if !args.list() && !args.update() && !args.pin() {
if change.is_remove() {
return Err(eyre::eyre!(
"The input with id: {} could not be removed.",
Expand Down Expand Up @@ -241,7 +232,7 @@ fn main() -> eyre::Result<()> {
buf.push_str(input.id());
}
let mut updater = Updater::new(app.root().text().clone(), inputs.clone());
updater.update();
updater.update_all_inputs_to_latest_semver();
let change = updater.get_changes();
if args.diff() {
let old = text.clone();
Expand All @@ -253,5 +244,36 @@ fn main() -> eyre::Result<()> {
app.root.apply(&change)?;
}
}
if let Command::Pin { id, rev } = args.subcommand() {
let lock = FlakeLock::from_default_path()?;

let target_rev = if let Some(rev) = rev {
rev.to_string()
} else {
lock.get_rev_by_id(id)?
};

let inputs = editor.list();
let mut buf = String::new();
for input in inputs.values() {
if !buf.is_empty() {
buf.push('\n');
}
buf.push_str(input.id());
}
let mut updater = Updater::new(app.root().text().clone(), inputs.clone());

updater.pin_input_to_ref(id, &target_rev);
let change = updater.get_changes();

if args.diff() {
let old = text.clone();
let new = change;
let diff = Diff::new(&old, &new);
diff.compare();
} else if args.apply() {
app.root.apply(&change)?;
}
}
Ok(())
}
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ pub enum FlakeEditError {
Io(#[from] std::io::Error),
#[error("The flake should be a root.")]
NotARoot,
#[error("There is an error in the Lockfile: {0}")]
LockError(String),
#[error("Deserialization Error: {0}")]
Serde(#[from] serde_json::Error),
// Reqwest Error
// #[error("Incorrect Channel")]
// IncorrectChannel(String),
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod diff;
pub mod edit;
pub mod error;
pub mod input;
pub mod lock;
pub mod state;
pub mod update;
pub mod walk;
Loading
Loading