Skip to content

Commit

Permalink
complete export, release v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lxl66566 committed Mar 5, 2024
1 parent 3396c61 commit de888c5
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 95 deletions.
58 changes: 58 additions & 0 deletions .github/workflow/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Release

permissions:
contents: write

on:
push:
tags:
- v[0-9]+.*

jobs:
create-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/create-gh-release-action@v1
with:
token: ${{ secrets.GH_TOKEN }}

upload-assets:
needs: create-release
strategy:
matrix:
include:
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install cross-compilation tools
uses: taiki-e/setup-cross-toolchain-action@v1
with:
target: ${{ matrix.target }}
- uses: taiki-e/upload-rust-binary-action@v1
with:
# (required) Comma-separated list of binary names (non-extension portion of filename) to build and upload.
# Note that glob pattern is not supported yet.
bin: urldecoder
# (optional) On which platform to distribute the `.tar.gz` file.
# [default value: unix]
# [possible values: all, unix, windows, none]
tar: unix
# (optional) On which platform to distribute the `.zip` file.
# [default value: windows]
# [possible values: all, unix, windows, none]
zip: windows
# (optional) Target triple, default is host triple.
target: ${{ matrix.target }}
# (required) GitHub token for uploading assets to GitHub Releases.
token: ${{ secrets.GH_TOKEN }}
71 changes: 1 addition & 70 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "wordinfo"
version = "0.1.0"
version = "1.0.0"
edition = "2021"
authors = ["lxl66566 <lxl66566@gmail.com>"]
description = "A CLI tool to info words from web"
description = "A CLI tool to info words from web."

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -14,8 +14,8 @@ colored = "2.1.0"
lazy_static = "1.4.0"
serde = { version = "1.0.197", features = ["derive"] }
toml = "0.8.10"
log = "0.4.20"
env_logger = "0.11.2"
# log = "0.4.20"
# env_logger = "0.11.2"
url = { version = "2.5.0", features = ["serde"] }
wana_kana = "3.0.0"
scraper = "0.18.1" # https://lib.rs/crates/scraper
Expand Down
58 changes: 56 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,60 @@

[English] | [简体中文](./docs/README.zh-CN.md)

A CLI tool to info words' meaning from web. It's a suppliment of [bakadict](https://github.com/flaribbit/bakadict), which info words from offline database.
wordinfo is a CLI tool to get information of words from web, including pronunciation, meaning, examples, etc.

You can define your own [CSS Selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_selectors).
It's the complement of [bakadict](https://github.com/flaribbit/bakadict): bakadict looks up words from local dictionary, while wordinfo gets word information from the web; bakadict supports only Japanese, while wordinfo supports multiple languages. (Now English and Japanese only, but can be extended to support more languages easily.)

wordinfo allows you to write your own [CSS Selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_selectors) to adapt word search to different languages and websites.

## Installation

Go to [Releases](https://github.com/lxl66566/wordinfo/releases) to download the platform-specific executable, or use [bpm](https://github.com/lxl66566/bpm) to install it.

## Use

```sh
Usage: wordinfo.exe [OPTIONS] <WORDS>...
wordinfo.exe <COMMAND>

Commands:
config config wordinfo, (not yet implemented)
export Export configuration file
help Print this message or the help of the given subcommand(s)

Arguments:
<WORDS>... words to look up

Options:
-e, --english English (default)
-j, --japanese Japanese
-s, --selector <SELECTOR> Which selector to use
-n, --no-url Do not output url
-h, --help Print help
-V, --version Print version

Examples:
wordinfo apple # Query for English `apple`, = wordinfo -e apple
wordinfo -j すき # Query Japanese `すき`, = wordinfo -j suki.
wordinfo -s oxf apple # Specify to query apple using the oxford selector.
```

wordinfo supports multiple languages, English is used by default. When querying Japanese, you can convert kana by typing romanization.

`wordinfo -s anything.. anything..` (any meaningless words) looks up the currently available CSS Selectors, and can be abbreviated when specifying a CSS Selector, e.g. `wordinfo -s oxf ... ` is equivalent to `wordinfo -s oxford ... `.

## Configuration

Run `wordinfo export` to export the default configuration file to `~/.config/wordinfo.toml` (Windows: `%userprofile%/.config/wordinfo.toml`), and edit the configuration items.

The currently adjustable items are:

```
default_language: default language
color: default color for each section of the output
en: English CSS Selectors
jp: Japanese CSS Selectors
```

To adjust the default CSS Selector used, just put it at the top. (Each of the three consecutive `[[en]]`, `[en.selector]`, `[en.delimiter]` belongs to one CSS Selector as a whole, and need to be moved together)
49 changes: 48 additions & 1 deletion docs/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,57 @@

wordinfo 是一个命令行工具,用于从网络上获取单词的详细信息,包括读音,释义,例句等。

它是 [bakadict](https://github.com/flaribbit/bakadict) 的补充:bakadict 从本地词典中查找单词,而 wordinfo 从网络中获取单词信息;bakadict 仅支持日语,而 wordinfo 支持多种语言。
它是 [bakadict](https://github.com/flaribbit/bakadict) 的补充:bakadict 从本地词典中查找单词,而 wordinfo 从网络中获取单词信息;bakadict 仅支持日语,而 wordinfo 支持多种语言。(当前仅支持英语、日语,但可扩展至其他语言。)

wordinfo 允许您编写自己的 [CSS Selector](https://developer.mozilla.org/zh-CN/docs/Web/CSS/CSS_selectors) 以适应不同语言、不同网站的单词查询。

## 安装

前往 [Releases](https://github.com/lxl66566/wordinfo/releases) 下载对应平台的可执行文件,或使用 [bpm](https://github.com/lxl66566/bpm) 安装。

## 使用

```sh
Usage: wordinfo.exe [OPTIONS] <WORDS>...
wordinfo.exe <COMMAND>

Commands:
config (暂未实现)
export 导出配置文件
help 打印帮助信息

Arguments:
<WORDS>... 需要查询的单词

Options:
-e, --english 英语(默认)
-j, --japanese 日语
-s, --selector <SELECTOR> 使用哪个 CSS Selector 来获取单词信息
-n, --no-url 不输出 URL
-h, --help 打印帮助信息
-V, --version 打印版本信息

Examples:
wordinfo apple # 查询 apple,= `wordinfo -e apple`
wordinfo -j すき # 查询 すき,= `wordinfo -j suki`
wordinfo -s oxf apple # 指定使用 oxford selector 查询 apple
```

wordinfo 支持多种语言,默认使用英语。查询日语时,输入罗马音能够进行假名转换。

`wordinfo -s afs...`(随便输点什么)可以查询当前可用 CSS Selector。指定 CSS Selector 时可以简写,例如 `wordinfo -s oxf ...` 等价于 `wordinfo -s oxford ...`

## 配置

执行 `wordinfo export` 导出默认配置文件到 `~/.config/wordinfo.toml`(Windows: `%userprofile%/.config/wordinfo.toml`),编辑配置项即可。

目前可调的项目有:

```
default_language: 默认语言
color: 每部分输出的默认颜色
en: 英语 CSS Selectors
jp: 日语 CSS Selectors
```

如果要调整默认使用的 CSS Selector,只需将其放到最前即可。(每三个连续的 `[[en]]`, `[en.selector]`, `[en.delimiter]` 属于一个 CSS Selector 整体,需要一起移动)
14 changes: 10 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ use serde::Serialize;

#[derive(Parser, Clone, Debug)]
#[command(author, version, about, long_about = None, after_help = r#"Examples:
wordinfo apple # Query for English `apple`, = wordinfo -e apple
wordinfo -j すき # Query Japanese `すき`, = wordinfo -j suki.
wordinfo -s oxf apple # Specify to query apple using the oxford selector.
"#)]
#[clap(args_conflicts_with_subcommands = true)]
pub struct Cli {
/// The words to info
/// words to look up
#[clap(required = true)]
pub words: Vec<String>,
/// English words
/// info English words
#[arg(short, long)]
#[clap(conflicts_with_all = &["japanese"])]
pub english: bool,
/// Japanese words
/// info Japanese words
#[arg(short, long)]
#[clap(conflicts_with_all = &["english"])]
pub japanese: bool,
Expand All @@ -23,15 +27,17 @@ pub struct Cli {
/// subcommand
#[command(subcommand)]
pub command: Option<Commands>,
/// not show url
/// do not output url
#[arg(short, long)]
pub no_url: bool,
}

/// Subcommand
#[derive(Subcommand, Debug, Clone)]
pub enum Commands {
/// config wordinfo, WIP
Config(Config),
/// export default config file
Export,
}

Expand Down
Loading

0 comments on commit de888c5

Please sign in to comment.