From ee6d2418f1b0b049d1b8b224b554af77dc9cc65e Mon Sep 17 00:00:00 2001 From: "K.B.Dharun Krishna" Date: Wed, 10 Apr 2024 19:35:51 +0530 Subject: [PATCH] Add BSD platform support and update workflows (#354) --- .github/dependabot.yml | 6 ++++++ .github/workflows/ci.yml | 8 ++++---- .github/workflows/gh-pages.yml | 2 +- .github/workflows/release.yml | 22 +++++++++++----------- completion/bash_tealdeer | 2 +- completion/fish_tealdeer | 2 +- completion/zsh_tealdeer | 3 +++ docs/src/usage.txt | 2 +- src/cache.rs | 3 +++ src/cli.rs | 2 +- src/types.rs | 34 ++++++++++++++++++++++++++-------- 11 files changed, 58 insertions(+), 28 deletions(-) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..8ac6b8c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "monthly" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 017a390..d8e33b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: toolchain: [stable, 1.64.0] runs-on: ${{ matrix.platform }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: toolchain: ${{ matrix.toolchain }} @@ -32,7 +32,7 @@ jobs: name: run clippy lints runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: toolchain: stable @@ -44,7 +44,7 @@ jobs: name: run rustfmt runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: toolchain: stable @@ -56,7 +56,7 @@ jobs: name: build docs runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup mdBook uses: peaceiris/actions-mdbook@v1 with: diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index dafba80..f4370ab 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -9,7 +9,7 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup mdBook uses: peaceiris/actions-mdbook@v1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 52aadc6..a3ae0fc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,7 +7,7 @@ jobs: create-release: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Create release for tag if: startsWith(github.ref, 'refs/tags/') run: | @@ -23,7 +23,7 @@ jobs: matrix: target: ["bash", "fish", "zsh"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Upload completion if: startsWith(github.ref, 'refs/tags/') run: | @@ -39,7 +39,7 @@ jobs: matrix: target: ["MIT", "APACHE"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Upload license if: startsWith(github.ref, 'refs/tags/') run: | @@ -65,14 +65,14 @@ jobs: - arch: "arm" libc: "musleabihf" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Pull Docker image run: docker pull messense/rust-musl-cross:${{ matrix.arch }}-${{ matrix.libc }} - name: Build in Docker run: docker run --rm -i -v "$(pwd)":/home/rust/src messense/rust-musl-cross:${{ matrix.arch }}-${{ matrix.libc }} cargo build --release - name: Strip binary run: docker run --rm -i -v "$(pwd)":/home/rust/src messense/rust-musl-cross:${{ matrix.arch }}-${{ matrix.libc }} musl-strip -s /home/rust/src/target/${{ matrix.arch }}-unknown-linux-${{ matrix.libc }}/release/tldr - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: "tealdeer-linux-${{ matrix.arch }}-${{ matrix.libc }}" path: "target/${{ matrix.arch }}-unknown-linux-${{ matrix.libc }}/release/tldr" @@ -80,14 +80,14 @@ jobs: build-macos: runs-on: macos-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup toolchain uses: dtolnay/rust-toolchain@master with: toolchain: stable - name: Build run: cargo build --release --target x86_64-apple-darwin --no-default-features --features webpki-roots - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: "tealdeer-macos-x86_64" path: "target/x86_64-apple-darwin/release/tldr" @@ -95,14 +95,14 @@ jobs: build-windows: runs-on: windows-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup toolchain uses: dtolnay/rust-toolchain@master with: toolchain: stable - name: Build run: cargo build --release --target x86_64-pc-windows-msvc - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: "tealdeer-windows-x86_64-msvc" path: "target/x86_64-pc-windows-msvc/release/tldr.exe" @@ -126,8 +126,8 @@ jobs: - macos-x86_64 - windows-x86_64-msvc steps: - - uses: actions/checkout@v3 - - uses: actions/download-artifact@v3 + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 - name: Upload binary if: startsWith(github.ref, 'refs/tags/') run: | diff --git a/completion/bash_tealdeer b/completion/bash_tealdeer index 1fc0655..d5420b6 100644 --- a/completion/bash_tealdeer +++ b/completion/bash_tealdeer @@ -14,7 +14,7 @@ _tealdeer() return ;; -p|--platform) - COMPREPLY=( $(compgen -W 'linux macos sunos windows android' -- "${cur}") ) + COMPREPLY=( $(compgen -W 'linux macos sunos windows android freebsd netbsd openbsd' -- "${cur}") ) return ;; --color) diff --git a/completion/fish_tealdeer b/completion/fish_tealdeer index dcb41c3..eb35e87 100644 --- a/completion/fish_tealdeer +++ b/completion/fish_tealdeer @@ -7,7 +7,7 @@ complete -c tldr -s h -l help -d 'Print the help message.' -f complete -c tldr -s v -l version -d 'Show version information.' -f complete -c tldr -s l -l list -d 'List all commands in the cache.' -f complete -c tldr -s f -l render -d 'Render a specific markdown file.' -r -complete -c tldr -s p -l platform -d 'Override the operating system.' -xa 'linux macos sunos windows android' +complete -c tldr -s p -l platform -d 'Override the operating system.' -xa 'linux macos sunos windows android freebsd netbsd openbsd' complete -c tldr -s L -l language -d 'Override the language' -x complete -c tldr -s u -l update -d 'Update the local cache.' -f complete -c tldr -l no-auto-update -d 'If auto update is configured, disable it for this run.' -f diff --git a/completion/zsh_tealdeer b/completion/zsh_tealdeer index 0d08745..fbab749 100644 --- a/completion/zsh_tealdeer +++ b/completion/zsh_tealdeer @@ -21,6 +21,9 @@ _tealdeer() { sunos windows android + freebsd + netbsd + openbsd ))' "($I -L --language)"{-L,--language}"[Override the language settings]:lang" "($I -u --update)"{-u,--update}"[Update the local cache]" diff --git a/docs/src/usage.txt b/docs/src/usage.txt index 74b3b2e..5ab6fd9 100644 --- a/docs/src/usage.txt +++ b/docs/src/usage.txt @@ -12,7 +12,7 @@ OPTIONS: -l, --list List all commands in the cache -f, --render Render a specific markdown file -p, --platform Override the operating system [possible values: linux, macos, - windows, sunos, osx, android] + windows, sunos, osx, android, freebsd, netbsd, openbsd] -L, --language Override the language -u, --update Update the local cache --no-auto-update If auto update is configured, disable it for this run diff --git a/src/cache.rs b/src/cache.rs index 48be75e..8fccb62 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -218,6 +218,9 @@ impl Cache { PlatformType::SunOs => "sunos", PlatformType::Windows => "windows", PlatformType::Android => "android", + PlatformType::FreeBsd => "freebsd", + PlatformType::NetBsd => "netbsd", + PlatformType::OpenBsd => "openbsd", } } diff --git a/src/cli.rs b/src/cli.rs index ed71ef8..3825245 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -40,7 +40,7 @@ pub(crate) struct Args { short = 'p', long = "platform", action = ArgAction::Append, - possible_values = ["linux", "macos", "windows", "sunos", "osx", "android"], + possible_values = ["linux", "macos", "windows", "sunos", "osx", "android", "freebsd", "netbsd", "openbsd"], )] pub platforms: Option>, diff --git a/src/types.rs b/src/types.rs index f3318a9..2de2d2b 100644 --- a/src/types.rs +++ b/src/types.rs @@ -14,6 +14,9 @@ pub enum PlatformType { SunOs, Windows, Android, + FreeBsd, + NetBsd, + OpenBsd, } impl fmt::Display for PlatformType { @@ -24,6 +27,9 @@ impl fmt::Display for PlatformType { Self::SunOs => write!(f, "SunOS"), Self::Windows => write!(f, "Windows"), Self::Android => write!(f, "Android"), + Self::FreeBsd => write!(f, "FreeBSD"), + Self::NetBsd => write!(f, "NetBSD"), + Self::OpenBsd => write!(f, "OpenBSD"), } } } @@ -38,8 +44,11 @@ impl str::FromStr for PlatformType { "sunos" => Ok(Self::SunOs), "windows" => Ok(Self::Windows), "android" => Ok(Self::Android), + "freebsd" => Ok(Self::FreeBsd), + "netbsd" => Ok(Self::NetBsd), + "openbsd" => Ok(Self::OpenBsd), other => Err(anyhow!( - "Unknown OS: {}. Possible values: linux, macos, osx, sunos, windows, android", + "Unknown OS: {}. Possible values: linux, macos, osx, sunos, windows, android, freebsd, netbsd, openbsd", other )), } @@ -52,13 +61,7 @@ impl PlatformType { Self::Linux } - #[cfg(any( - target_os = "macos", - target_os = "freebsd", - target_os = "netbsd", - target_os = "openbsd", - target_os = "dragonfly" - ))] + #[cfg(any(target_os = "macos", target_os = "dragonfly"))] pub fn current() -> Self { Self::OsX } @@ -73,6 +76,21 @@ impl PlatformType { Self::Android } + #[cfg(any(target_os = "freebsd"))] + pub fn current() -> Self { + Self::FreeBsd + } + + #[cfg(any(target_os = "netbsd"))] + pub fn current() -> Self { + Self::NetBsd + } + + #[cfg(any(target_os = "openbsd"))] + pub fn current() -> Self { + Self::OpenBsd + } + #[cfg(not(any( target_os = "linux", target_os = "macos",