Skip to content

Commit

Permalink
Add BSD platform support and update workflows (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbdharun authored Apr 10, 2024
1 parent c8f2408 commit ee6d241
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 28 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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: |
Expand All @@ -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: |
Expand All @@ -65,44 +65,44 @@ 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"

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"

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"
Expand All @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion completion/bash_tealdeer
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion completion/fish_tealdeer
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions completion/zsh_tealdeer
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ OPTIONS:
-l, --list List all commands in the cache
-f, --render <FILE> Render a specific markdown file
-p, --platform <PLATFORMS> Override the operating system [possible values: linux, macos,
windows, sunos, osx, android]
windows, sunos, osx, android, freebsd, netbsd, openbsd]
-L, --language <LANGUAGE> Override the language
-u, --update Update the local cache
--no-auto-update If auto update is configured, disable it for this run
Expand Down
3 changes: 3 additions & 0 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ impl Cache {
PlatformType::SunOs => "sunos",
PlatformType::Windows => "windows",
PlatformType::Android => "android",
PlatformType::FreeBsd => "freebsd",
PlatformType::NetBsd => "netbsd",
PlatformType::OpenBsd => "openbsd",
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<PlatformType>>,

Expand Down
34 changes: 26 additions & 8 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ pub enum PlatformType {
SunOs,
Windows,
Android,
FreeBsd,
NetBsd,
OpenBsd,
}

impl fmt::Display for PlatformType {
Expand All @@ -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"),
}
}
}
Expand All @@ -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
)),
}
Expand All @@ -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
}
Expand All @@ -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",
Expand Down

0 comments on commit ee6d241

Please sign in to comment.