Commit graph

364 commits

Author SHA1 Message Date
Danilo Bargen
4a92bed585 Improve API by introducing a PlatformType struct 2021-12-06 00:35:18 +01:00
Danilo Bargen
3b69359757 Support all platform when listing pages 2021-12-06 00:35:18 +01:00
Danilo Bargen
1c05333de6 Allow setting platform to all
The goal is supporting the special `all` platform that results in pages
for all platforms being listed when calling `--list`. It's part of the
tldr client specification.

However, `All` should not be a variant of the `PlatformType` enum,
because `Current` isn't a `PlatformType` either. Thus, we accept the
string `all` but convert it into the current platform when parsing.

For consistency, the same is done when no platform is specified, by
introducing yet another possible value `current` which is used by
default. This way, we get rid of the `Option`.

To simplify handling of os / platform arguments, a conflict between
`--platform` and `--os` was introduced.
2021-12-06 00:35:14 +01:00
Danilo Bargen
1a3624d011
Introduce command_or_file arg group (#230)
This allows to say "this command line parameter requires either a
command or a raw file".

Fixes #219.
2021-12-05 20:45:35 +01:00
Danilo Bargen
72d753c52b
Add "macos" alias for "osx" (#215)
The Apple computer operating system was renamed from "OS X" to "macOS"
in 2016. We should accept "macos" instead of "osx" in all our CLI APIs,
and the docs should also mention this alias instead of "osx".

For backwards compatibility and for compatibility with the tldr client
specification, we should still accept "osx" though.
2021-12-05 16:38:35 +01:00
Danilo Bargen
023a9d2079
Lowercase page names before lookup (#227) 2021-12-05 14:31:03 +01:00
Danilo Bargen
02a395ad13
Remove last traces of short -p pager flag (#228)
I missed some occurrences in #217.
2021-12-05 14:15:49 +01:00
Danilo Bargen
2684727eaa
Add helper functions: print_warning / print_error (#223)
These functions prepend a consistend prefix and they also use colors
(when enabled).

Messages are written to stderr.
2021-12-05 14:00:59 +01:00
Danilo Bargen
0fbc95cb71
Rename -o / --os to -p / --platform (#217)
This makes it compliant with the client spec.

The `-p` flag was previously used for the pager, using the pager now
requires using the long flag (`--pager`). Alternatively the pager can be
configured through the config file.

This commit also renames OsType to PlatformType.
2021-12-05 13:28:58 +01:00
Danilo Bargen
02c2d6709a
Run cargo update (#226)
This fixes a vulnerability in tokio (RUSTSEC-2021-0124).
2021-12-04 21:47:58 +01:00
Danilo Bargen
9c90f8ba7a
Fix clippy lints added in 1.57 (#225) 2021-12-04 21:34:06 +01:00
Danilo Bargen
746d4dadda
Fix clippy warnings (#222)
- Silence warning about excessive bools
- Implement recommendation about unneeded Option in return type
2021-10-24 23:30:10 +02:00
Marcin Puc
3beed4ad48
Simplify clap derive definition (#221)
- Use `possible_values`
- Change `render` field type to `PathBuf`
- Add comment about explicit field names
2021-10-24 23:17:43 +02:00
Danilo Bargen
cea3bcdc3f
Update benchmarks (#216)
New numbers with clap instead of docopt (current master branch). This
change improved performance considerably.
2021-10-18 00:21:43 +02:00
Danilo Bargen
c6bc6f8183
Merge pull request #108 from dbrgn/clap
Argument parsing: Switch from docopt to clap

Fixes #106.
2021-10-17 22:35:55 +02:00
Danilo Bargen
618ecaf71f Add @niklasmohrin to crate authors 2021-10-17 22:23:35 +02:00
Danilo Bargen
371f1d2ace Help: Add a link to the online docs 2021-10-17 22:22:45 +02:00
Danilo Bargen
6823e271a0 Disable clap colors for now
May be re-introduced if clap adds a `DisableColoredHelp` setting.

Relevant discussion:

- https://github.com/clap-rs/clap/pull/2845#issuecomment-945185102
- https://github.com/dbrgn/tealdeer/pull/108#issuecomment-945182471
2021-10-17 22:10:08 +02:00
Danilo Bargen
fc726011d1 Move free-standing get_os function to OsType::current 2021-10-17 21:16:50 +02:00
Danilo Bargen
8833b6b401 Rename -m / --markdown to -r / --raw
That flag name is clearer: We output raw page data without processing.
2021-10-17 21:12:08 +02:00
Danilo Bargen
ee0d32d3de CI: Ensure that usage string is always up to date 2021-10-17 21:12:08 +02:00
Danilo Bargen
6d77483ad5 Implement Default for ColorOptions 2021-10-17 21:12:08 +02:00
Danilo Bargen
5ad7dcfa34 Argument parsing: Switch from docopt to clap 2021-10-17 21:12:08 +02:00
Danilo Bargen
6300b6a24f
Merge pull request #214 from dbrgn/remove-udeps
Remove unused dependencies
2021-10-17 19:48:05 +02:00
Danilo Bargen
84227937ae Remove some optional zip features
By getting rid of the bzip2 and time features, we reduce the number of
dependencies. The official tldr pages archive uses deflate compression,
so that should be sufficient.
2021-10-16 20:40:40 +02:00
Danilo Bargen
0ebd727a32 Remove tar dependency
It's unused since #213.
2021-10-16 20:36:53 +02:00
Danilo Bargen
f7da0b028d Merge pull request #213 from invakid404/use-proper-tldr-archive
Download tldr pages from proper archive URL.
2021-10-16 20:10:00 +02:00
invakid404
62725fca5f When clearing cache, only delete pages, not entire cache dir
Squashed commits:

- chore: wipe only pages instead of entire cache dir
- fix: only delete dir if it exists
- chore: try to make variable names less confusing
- chore: display error as well
2021-10-16 20:09:32 +02:00
invakid404
006ec6f3c0 Switch to recommended tldr-pages archive URL
Instead of downloading the GitHub repository archive, download the pages
from the official URL instead.

Squashed commits:

- chore: use recommended tldr-pages archive url
- chore: extract pages dir to constant
- chore(deps): install zip crate
- feat: use zip crate to unpack archive
- chore(deps): drop flate2
2021-10-16 20:09:32 +02:00
Danilo Bargen
7bd08e35d1 Refactor cache freshness checks
- Create explicit CacheFreshness enum
- Do not exit inside `check_cache` function, this prevents further
  actions if the cache isn't found

Co-authored-by: invakid404 <invakid404@riseup.net>
2021-10-16 20:09:16 +02:00
rnd
32cc6d5893
Use default style if user-defined style is missing (#210)
Changes the serde configuration of the `RawConfig` struct to utilize
a custom `Default` implementation to initialize new objects. This
implementation contains the default style set as it was previously
provided through the implementation of `RawConfig::new()`.

This allows to utilize the default configuration until the user
overwrites the related `RawStyleConfig` field, e.g. the description
highlighting.

Fixes #149.
2021-10-16 17:38:07 +02:00
Danny Mösch
3c92cff865
Add test for hightlighting with empty command (#178) 2021-10-16 17:20:07 +02:00
Danilo Bargen
9eca2fe5db Update copyright year 2021-10-16 13:06:28 +02:00
Tsvetomir Bonev
3f49100307
Docs: Add funtoo package to list (#208) 2021-10-03 16:10:30 +02:00
Danilo Bargen
e84fce6f90
Use tree-style imports (#204) 2021-09-13 09:06:21 +02:00
Danilo Bargen
b0449dc6bf
Merge pull request #203 from dbrgn/update-deps
Update dependencies
2021-09-12 23:29:06 +02:00
Danilo Bargen
07dc5c6bf4 Upgrade predicates and assert_cmd: 1 → 2 2021-09-12 21:12:00 +02:00
Danilo Bargen
85ab38d892 Remove dev dependency on remove_dir_all
It's a transitive dependency of the `tempdir` crate. It was pinned to a
specific version to achieve compatibility with Rust 1.39, but we now run
on 1.53.
2021-09-12 21:06:06 +02:00
Danilo Bargen
7aa111e727 Upgrade reqwest: 0.10 → 0.11
This increases the release binary size by 144 KiB, but it reduces the
number of transitive dependencies from 152 to 140.
2021-09-12 20:56:24 +02:00
Danilo Bargen
b359fd8e5b Upgrade pager: 0.15 → 0.16 2021-09-12 20:42:10 +02:00
Danilo Bargen
4376162914 Upgrade env_logger: 0.7 → 0.9 2021-09-12 20:40:08 +02:00
Danilo Bargen
ffc30d1243 Run cargo update 2021-09-12 20:35:00 +02:00
Danilo Bargen
a811788b31
Merge pull request #189 from niklasmohrin/simplify_highlight_commands
Refactor formatting code
2021-09-12 20:31:45 +02:00
Danny Mösch
1471b1d97b
Create cache directory path if it does not exist (#174)
Fixes #167
2021-09-12 20:28:22 +02:00
Niklas Mohrin
3ac087ae41
Final touches for formatting refactor
- Rename: `yield_snippet` => `process_snippet`
- Rename: `HighlightingSnippet` => `PageSnippet`
2021-09-08 15:02:25 +02:00
Niklas Mohrin
b216a63c64
Add integration test for non-ascii page rendering
Although this did not fail on old master, it is still an important case
to test. Actually, this test doesn't even break when introducing some
errors that fail i18n unit tests, unless the command name itself is
non-ascii.
2021-09-08 14:44:10 +02:00
Niklas Mohrin
22baa455b5
Update inkscape-default.expected 2021-09-08 14:44:09 +02:00
Niklas Mohrin
743998a75f
Reorder functions in formatter.rs
As someone reading this file for the first time, I would want to see the
only public and most general function first and find the specifics
further down instead of having to look for the "module entry" first.
2021-09-08 14:44:09 +02:00
Niklas Mohrin
808ad7ff30
Extract output logic for pages into own module
This moves `print_page` from `main.rs` and `print_snippet` from
`formatter.rs` into a new file `output.rs`. To decompose `print_snippet`
from `print_lines`, the latter now takes the `yield_snippet` callable as
an argument (similar to how the helper methods got a hold of it). In
order for this to work, callers have to provide a function that is
generic over all possible snippet lifetimes.
2021-09-08 14:40:32 +02:00
Niklas Mohrin
e8b1c9e801
Rename Tokenizer to LineIterator
This also replaces the `next_token` method with the `next` method from
the `Iterator` trait.
2021-09-08 14:39:57 +02:00