Skip to content

Commit

Permalink
feat: add support for common platform flag
Browse files Browse the repository at this point in the history
Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com>
  • Loading branch information
kbdharun committed Feb 20, 2024
1 parent 06b3e7a commit 015b01f
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 6 deletions.
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 freebsd netbsd openbsd' -- "${cur}") )
COMPREPLY=( $(compgen -W 'common 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 freebsd netbsd openbsd'
complete -c tldr -s p -l platform -d 'Override the operating system.' -xa 'common 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
1 change: 1 addition & 0 deletions completion/zsh_tealdeer
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ _tealdeer() {
"($I -l --list)"{-l,--list}"[List all commands in the cache]"
"($I -f --render)"{-f,--render}"[Render a specific markdown file]:file:_files"
"($I -p --platform)"{-p,--platform}'[Override the operating system]:platform:((
common
linux
macos
sunos
Expand Down
4 changes: 2 additions & 2 deletions docs/src/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ ARGS:
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, freebsd, netbsd, openbsd]
-p, --platform <PLATFORMS> Override the operating system [possible values: common, linux,
macos, 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
1 change: 1 addition & 0 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ impl Cache {
/// Return the platform directory.
fn get_platform_dir(platform: PlatformType) -> &'static str {
match platform {
PlatformType::Common => "common",
PlatformType::Linux => "linux",
PlatformType::OsX => "osx",
PlatformType::SunOs => "sunos",
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", "freebsd", "netbsd", "openbsd"],
possible_values = ["common", "linux", "macos", "windows", "sunos", "osx", "android", "freebsd", "netbsd", "openbsd"],
)]
pub platforms: Option<Vec<PlatformType>>,

Expand Down
11 changes: 10 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use serde_derive::{Deserialize, Serialize};
#[serde(rename_all = "lowercase")]
#[allow(dead_code)]
pub enum PlatformType {
Common,
Linux,
OsX,
SunOs,
Expand All @@ -22,6 +23,7 @@ pub enum PlatformType {
impl fmt::Display for PlatformType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Common => write!(f, "Common"),
Self::Linux => write!(f, "Linux"),
Self::OsX => write!(f, "macOS / BSD"),
Self::SunOs => write!(f, "SunOS"),
Expand All @@ -39,6 +41,7 @@ impl str::FromStr for PlatformType {

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"common" => Ok(Self::Common),
"linux" => Ok(Self::Linux),
"osx" | "macos" => Ok(Self::OsX),
"sunos" => Ok(Self::SunOs),
Expand All @@ -48,7 +51,7 @@ impl str::FromStr for PlatformType {
"netbsd" => Ok(Self::NetBSD),
"openbsd" => Ok(Self::OpenBSD),
other => Err(anyhow!(
"Unknown OS: {}. Possible values: linux, macos, osx, sunos, windows, android, freebsd, netbsd, openbsd",
"Unknown OS: {}. Possible values: common, linux, macos, osx, sunos, windows, android, freebsd, netbsd, openbsd",
other
)),
}
Expand Down Expand Up @@ -91,7 +94,13 @@ impl PlatformType {
Self::OpenBSD
}

#[cfg(any(target_os = "common",))]
pub fn current() -> Self {
Self::Common
}

#[cfg(not(any(
target_os = "common",
target_os = "linux",
target_os = "macos",
target_os = "freebsd",
Expand Down

0 comments on commit 015b01f

Please sign in to comment.