Commit graph

174 commits

Author SHA1 Message Date
Niklas Mohrin
ffce919049
Update ARCHIVE_URL
When this code was written, the client specification instructed clients
that they MUST download pages from the tldr.sh domain. However, this
domain was deprecated and shut down in December 2025.
2026-01-24 00:53:17 +01:00
Danilo Bargen
e722b4f92e
Rename main branch (#239) 2021-12-30 22:39:27 +01:00
Danilo Bargen
ed3d1ea9af Always add empty line before concatenating patch file 2021-12-30 21:09:37 +01:00
Danilo Bargen
fb40974616 Cache: Add tests for PageLookupResult::reader
Co-authored-by: Dalton Maahs <dalton.maahs@yourbind.com>
2021-12-30 00:01:31 +01:00
Danilo Bargen
0ef31d1f17 Concatenate page and patch bytes before processing
This way a patch file does not need a well-formed header anymore.

Fixes #181.
2021-12-30 00:01:31 +01:00
Danilo Bargen
6508ec6ac6 Ensure that default custom_pages_dir ends with trailing slash 2021-12-20 00:26:19 +01:00
Danilo Bargen
00ec281b9b Include custom pages directory in --show-paths command 2021-12-20 00:25:48 +01:00
Danilo Bargen
876f390ac6 Clap: Enable colored error messages 2021-12-11 18:00:19 +01:00
Danilo Bargen
69f4808214 Clap: Hide deprecated -o/--os argument from help 2021-12-11 18:00:19 +01:00
Danilo Bargen
25d771778a Update clap to 3.0.0-rc.4 2021-12-11 17:36:28 +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
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
371f1d2ace Help: Add a link to the online docs 2021-10-17 22:22:45 +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
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
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
Danilo Bargen
e84fce6f90
Use tree-style imports (#204) 2021-09-13 09:06:21 +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
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
Niklas Mohrin
62e82461cb
Refactor most of formatter.rs
This includes
- adding the `HighlightingSnippet` enum as a common ground for
  highlighting and printing code to communicate
- decomposing `print_lines` accordingly
- clearing up `highlight_code_segment` (previously `highlight_command`)
- adding unit tests (now that they can reason about
  `HighlightingSnippet`s instead of having to output on the integration
  test level
2021-09-08 14:39:51 +02:00
Niklas Mohrin
cdbca5c53b
Add FindFrom extension trait to str to start searching at a byte offset.
This also moves the contents of `dedup.rs` into a shared module `extensions`.
2021-09-08 14:38:31 +02:00
Wesley Klop
8051c3169a
Implement support for italics (#197)
Closes #146.
2021-09-06 17:01:55 +02:00
Marcin Puc
a4ac910e86 Add various small refactorings 2021-08-29 16:12:24 +02:00
Niklas Mohrin
d5d3d20451
Run clippy on stable with msrv setting instead of on msrv (#200) 2021-08-17 19:40:35 +02:00
Sondre Nilsen
feb20d8c5c Add WriteError type, convert print_lines to return a result 2021-05-25 16:38:28 +02:00
Sondre Nilsen
06f771f64d Use unbuffered IO for faster printing to stdout 2021-05-25 16:37:57 +02:00
Dalton
4d4c7b6a5d
Fix clippy warnings (#188)
* Fix clippy warnings
* Update toolchain for CI workflows fmt and clippy
2021-05-11 13:28:26 +02:00
Dalton
388deac079
Send all progress logging messages to stderr (#171)
- Change logging messages to go to stderr
- Updated tests to expect these messages in stderr instead of stdout
- Changed test_markdown_rendering to no longer rely on the tldr pages repo
2021-05-10 09:17:13 +02:00
Dalton
0fce79f8ed
Add unit tests for custom pages / patches (#183) 2021-04-23 20:06:44 +02:00
ギャラ
42816d3d09
Fix order of derive helper attributes (#179) 2021-04-19 15:09:07 +02:00
Danny Mösch
2a304b17f2
Fix clippy warnings (#173) 2021-04-18 19:27:25 +02:00
Dalton
07c715656f
Support custom pages and patches (#142)
Allow adding, overriding and extending custom pages.

Fixes #98.
2021-04-18 19:22:41 +02:00