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
58 changes: 36 additions & 22 deletions .github/workflows/build-for-release.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: Build assets for a Release

on:
release:
types: [published]
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"

jobs:
build-artifact:
Expand All @@ -12,39 +13,52 @@ jobs:
os: [ubuntu-latest, windows-latest]
include:
- os: ubuntu-latest
exe_suffix: ""
target: x86_64-unknown-linux-musl
- os: windows-latest
exe_suffix: ".exe"
target: x86_64-pc-windows-msvc
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: ${{ matrix.target }}
override: true

- name: Cache dependencies
uses: Swatinem/rust-cache@v1
- uses: actions-rs/cargo@v1
uses: Swatinem/rust-cache@v2

- name: Build
run: cargo build --release --locked --verbose --target ${{ matrix.target }}

- name: Pack completions
if: matrix.os == 'ubuntu-latest' # Runs only once
run: zip -r completions.zip completions

- name: Upload asset on Linux
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: startsWith(github.ref, 'refs/tags/') && matrix.os == 'ubuntu-latest'
with:
command: build
args: --release --locked --verbose --target ${{ matrix.target }}
- name: Upload asset
uses: actions/[email protected]
files: |
target/${{ matrix.target }}/release/dotter
completions.zip

- name: Upload asset on Windows
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: startsWith(github.ref, 'refs/tags/') && matrix.os == 'windows-latest'
with:
asset_path: target/${{ matrix.target }}/release/dotter${{ matrix.exe_suffix }}
asset_name: dotter${{ matrix.exe_suffix }}
asset_content_type: application/octet-stream
upload_url: ${{ github.event.release.upload_url }}
files: target/${{ matrix.target }}/release/dotter.exe

cargo-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: cargo login ${CRATES_IO_TOKEN}
env:
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
- run: cargo publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: cargo login ${CRATES_IO_TOKEN}
env:
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
- run: cargo publish
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# Generated by build.rs
completions/
11 changes: 11 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ license = "Unlicense"
anyhow = "1.*"
clap = { version = "4.0.26", features = ["derive"] }
clap_complete = "4.0.5"
clap_complete_nushell = "0.1.10"
crossterm = "0.25.0"
diff = "0.1.*"
handlebars = { version = "4.*", features = ["script_helper"] }
Expand All @@ -38,6 +39,11 @@ mockall = "0.11.3"
# Enable this instead for better failure messages (on nightly only)
# mockall = { version = "0.9.*", features = ["nightly"] }

[build-dependencies]
clap = { version = "4.0.26", features = ["derive"] }
clap_complete = "4.0.5"
clap_complete_nushell = "0.1.10"

[target.'cfg(windows)'.dependencies]
dunce = "1.*"

Expand Down
28 changes: 28 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#[allow(dead_code)]
#[path = "src/args.rs"]
mod args;

use self::args::Options;
use clap::CommandFactory;
use clap_complete::generate_to;
use clap_complete::Shell::*;
use clap_complete_nushell::Nushell;
use std::fs;
use std::io;

fn main() -> io::Result<()> {
let cmd = &mut Options::command();
let name = "dotter";
let dir = "completions";

fs::create_dir_all(dir)?;

generate_to(Bash, cmd, name, dir)?;
generate_to(Zsh, cmd, name, dir)?;
generate_to(Elvish, cmd, name, dir)?;
generate_to(Fish, cmd, name, dir)?;
generate_to(PowerShell, cmd, name, dir)?;
generate_to(Nushell, cmd, name, dir)?;

Ok(())
}
89 changes: 58 additions & 31 deletions src/args.rs
Original file line number Diff line number Diff line change
@@ -1,89 +1,78 @@
use std::io;
use std::path::PathBuf;

use clap::{Parser, Subcommand};
use clap_complete::Shell;
use clap::{Command, Parser, Subcommand, ValueEnum};
use clap_complete::Generator;

/// A small dotfile manager.
#[derive(Debug, Parser, Default, Clone)]
#[clap(author, version, about, long_about = None)]
pub struct Options {
/// Location of the global configuration
#[clap(
short,
long,
value_parser,
default_value = ".dotter/global.toml",
global = true
)]
#[arg(short, long, default_value = ".dotter/global.toml", global = true)]
pub global_config: PathBuf,

/// Location of the local configuration
#[clap(
short,
long,
value_parser,
default_value = ".dotter/local.toml",
global = true
)]
#[arg(short, long, default_value = ".dotter/local.toml", global = true)]
pub local_config: PathBuf,

/// Location of cache file
#[clap(long, value_parser, default_value = ".dotter/cache.toml")]
#[arg(long, default_value = ".dotter/cache.toml")]
pub cache_file: PathBuf,

/// Directory to cache into.
#[clap(long, value_parser, default_value = ".dotter/cache")]
#[arg(long, default_value = ".dotter/cache")]
pub cache_directory: PathBuf,

/// Location of optional pre-deploy hook
#[clap(long, value_parser, default_value = ".dotter/pre_deploy.sh")]
#[arg(long, default_value = ".dotter/pre_deploy.sh")]
pub pre_deploy: PathBuf,

/// Location of optional post-deploy hook
#[clap(long, value_parser, default_value = ".dotter/post_deploy.sh")]
#[arg(long, default_value = ".dotter/post_deploy.sh")]
pub post_deploy: PathBuf,

/// Location of optional pre-undeploy hook
#[clap(long, value_parser, default_value = ".dotter/pre_undeploy.sh")]
#[arg(long, default_value = ".dotter/pre_undeploy.sh")]
pub pre_undeploy: PathBuf,

/// Location of optional post-undeploy hook
#[clap(long, value_parser, default_value = ".dotter/post_undeploy.sh")]
#[arg(long, default_value = ".dotter/post_undeploy.sh")]
pub post_undeploy: PathBuf,

/// Dry run - don't do anything, only print information.
/// Implies -v at least once
#[clap(short = 'd', long = "dry-run", global = true)]
#[arg(short = 'd', long = "dry-run", global = true)]
pub dry_run: bool,

/// Verbosity level - specify up to 3 times to get more detailed output.
/// Specifying at least once prints the differences between what was before and after Dotter's run
#[clap(short = 'v', long = "verbose", action = clap::ArgAction::Count, global = true)]
#[arg(short = 'v', long = "verbose", action = clap::ArgAction::Count, global = true)]
pub verbosity: u8,

/// Quiet - only print errors
#[clap(short, long, value_parser, global = true)]
#[arg(short, long, global = true)]
pub quiet: bool,

/// Force - instead of skipping, overwrite target files if their content is unexpected.
/// Overrides --dry-run.
#[clap(short, long, value_parser, global = true)]
#[arg(short, long, global = true)]
pub force: bool,

/// Assume "yes" instead of prompting when removing empty directories
#[clap(short = 'y', long = "noconfirm", global = true)]
#[arg(short = 'y', long = "noconfirm", global = true)]
pub noconfirm: bool,

/// Take standard input as an additional files/variables patch, added after evaluating
/// `local.toml`. Assumes --noconfirm flag because all of stdin is taken as the patch.
#[clap(short, long, value_parser, global = true)]
#[arg(short, long, global = true)]
pub patch: bool,

/// Amount of lines that are printed before and after a diff hunk.
#[clap(long, value_parser, default_value = "3")]
#[arg(long, default_value = "3")]
pub diff_context_lines: usize,

#[clap(subcommand)]
#[command(subcommand)]
pub action: Option<Action>,
}

Expand All @@ -107,12 +96,50 @@ pub enum Action {

/// Generate shell completions
GenCompletions {
/// Set the shell for generating completions [values: bash, elvish, fish, powerShell, zsh]
/// Set the shell for generating completions [values: bash, elvish, fish, powershell, zsh, nushell]
#[clap(long, short)]
shell: Shell,
},
}

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

impl Generator for Shell {
fn file_name(&self, name: &str) -> String {
use clap_complete::Shell::*;
use clap_complete_nushell::Nushell;
match self {
Self::Bash => Bash.file_name(name),
Self::Elvish => Elvish.file_name(name),
Self::Fish => Fish.file_name(name),
Self::Powershell => PowerShell.file_name(name),
Self::Zsh => Zsh.file_name(name),
Self::Nushell => Nushell.file_name(name),
}
}

fn generate(&self, cmd: &Command, buf: &mut dyn io::Write) {
use clap_complete::Shell::*;
use clap_complete_nushell::Nushell;
match self {
Self::Bash => Bash.generate(cmd, buf),
Self::Elvish => Elvish.generate(cmd, buf),
Self::Fish => Fish.generate(cmd, buf),
Self::Powershell => PowerShell.generate(cmd, buf),
Self::Zsh => Zsh.generate(cmd, buf),
Self::Nushell => Nushell.generate(cmd, buf),
}
}
}

pub fn get_options() -> Options {
let mut opt = Options::parse();
if opt.dry_run {
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Otherwise, run `dotter undeploy` as root, remove cache.toml and cache/ folders,
.block_on(watch::watch(opt))
.context("watch repository")?;
}

args::Action::GenCompletions { shell } => {
generate(
shell,
Expand Down