pt-tools

command module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2024 License: MIT Imports: 1 Imported by: 0

README

pt-tools

pt-tools 是一个专为私人追踪器 (PT) 站点设计的命令行工具,旨在帮助用户自动化处理与 PT 站点相关的任务,例如筛选免费种子、与 PT 站点 API 交互,以及管理数据库操作。

功能特性

  • 灵活的运行模式:支持单次执行和持续监控模式。
  • Shell 补全支持:提供 Bash 和 Zsh 的补全功能。
  • 可定制的配置:轻松初始化和自定义配置文件。
  • 数据库管理:支持数据库初始化、备份和查询等操作。

安装方法

从源码构建
  1. 克隆代码库:

    git clone https://github.com/sunerpy/pt-tools.git
    cd pt-tools
    
  2. 构建二进制文件:

    go build -o pt-tools .
    
  3. 将二进制文件移动到系统 PATH

    mv pt-tools /usr/local/bin/
    

使用说明

基本命令结构
pt-tools [命令] [选项]
可用命令
命令 描述
completion 生成 Bash 和 Zsh 的补全脚本
config 管理配置文件
db 执行数据库相关操作
run 以单次或持续模式运行工具
task 管理计划任务(开发中)
help 显示帮助信息
全局选项
选项 描述
-c, --config 配置文件路径(默认: $HOME/.pt-tools/config.toml
-h, --help 显示命令的帮助信息
-t, --toggle 切换某些功能(占位符)

命令详解

run

run 命令允许用户以不同的模式运行工具。

示例

  1. 单次运行模式:

    pt-tools run --mode=single
    

    工具运行一次后退出。

  2. 持续运行模式:

    pt-tools run --mode=persistent
    

    工具持续运行,按设定的时间间隔重复执行任务。

用法

pt-tools run [选项]
选项 描述
-m, --mode 运行模式:singlepersistent(默认: single
-h, --help 显示 run 命令的帮助信息

completion

生成用于 Bash 和 Zsh 的 Shell 补全脚本。

示例

  • 对于 Bash:

    pt-tools completion bash
    source <(pt-tools completion bash)
    
  • 对于 Zsh:

    pt-tools completion zsh
    source <(pt-tools completion zsh)
    

用法

pt-tools completion [bash|zsh]

config

管理工具的配置文件。

示例

pt-tools config init

$HOME/.pt-tools/config.toml 路径下初始化默认配置文件。


db

执行数据库相关操作,例如初始化、备份或查询。

示例

pt-tools db init

配置说明

pt-tools 的配置优先级从高到低如下:

  1. 环境变量

    • 环境变量的优先级高于配置文件。即使使用了 --config 指定配置文件,环境变量的值仍然会覆盖文件中的相应配置项。

    • 环境变量的名称需与配置键名一致(不区分大小写)。

    • 示例:

      export DEFAULT_INTERVAL=10
      
  2. 指定的配置文件

    • 如果使用 -c 或者 --config 显式指定配置文件路径,pt-tools 将读取该文件,并使用文件中的值。

    • 示例:

      pt-tools --config /path/to/config.toml
      
  3. 默认的配置文件

    • 如果未显式指定 --config,工具会在默认路径(如 $HOME/.pt-tools/config.toml)查找配置文件,并使用文件中的值。
  4. 程序内置默认值

    • 如果命令行参数、环境变量和配置文件中均未提供某项配置,且不存在$HOME/.pt-tools/config.tomlpt-tools 将创建初始化的默认配置文件。


注意事项
  1. 环境变量优先级高于配置文件:

    • 即使显式指定了 --config,环境变量中设置的值仍然会覆盖配置文件中的值。
    • 如果不希望环境变量覆盖配置文件,请确保未设置对应的环境变量。
  2. 命令行标志始终优先于环境变量和配置文件,用于动态覆盖配置项。


高级使用

启用 Shell 补全
Bash
  1. 生成 Bash 补全脚本:

    pt-tools completion bash > /etc/bash_completion.d/pt-tools
    
  2. 重新加载 Shell 或直接加载补全脚本:

    source /etc/bash_completion.d/pt-tools
    
Zsh
  1. 确保已启用补全功能:

    echo "autoload -U compinit; compinit" >> ~/.zshrc
    
  2. 生成 Zsh 补全脚本:

    pt-tools completion zsh > "${fpath[1]}/_pt-tools"
    
  3. 启动新 Shell 会话。


贡献

欢迎贡献代码!请通过 GitHub 仓库 提交问题或拉取请求。


许可证

本项目基于 MIT 许可证 进行许可。

Documentation

Overview

Copyright © 2024 sunerpy <nkuzhangshn@gmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Directories

Path Synopsis
thirdpart

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL