英文:
Can't install CLI tool to be used globally in the terminal on Windows
问题
I've made a Rust CLI tool and want to provide download instructions for it to users.
The tool lets you run commands like convert <some args>
and lets you convert between numbers with different bases. The key here is I'm trying to enable you running the commands with the keyword convert
globally instead of a user having to be in the project directory and run cargo run <args>
or ./main <args>
.
My Cargo.toml
looks like this:
[package]
name = "converter_cli"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
[[bin]]
name = "convert"
path = "src/main.rs"
Currently, after some research, I've written these instructions which work for my computer (Mac M1):
- Make sure you have Rust installed on your system. If you don't, use this link.
- Clone the repo:
git clone https://github.com/mattrltrent/base_converter
. - In the project directory, run
cargo build --release
. - In the project directory, run
cargo install --path .
(don't miss the ending.
). - You should now be able to run the tool globally. To be sure, check if you can run
convert version
.
However, I've ran these instructions on a Windows PC and I get the error "Invalid drive specification" when trying to run convert <args>
.
Is there a better way to make this distributable (without publishing it as a Cargo crate) for Linux, Windows, and MacOS in one unified way? Or if not, why don't these instructions work for Windows?
If relevant, my file structure is as follows:
assets
-> <random image assets>
src
-> conversions.rs
-> errors.rs
-> main.rs
target
.gitignore
Cargo.lock
Cargo.toml
README.md
英文:
I've made a Rust CLI tool and want to provide download instructions for it to users.
The tool lets you run commands like convert <some args>
and lets you convert between numbers with different bases. The key here is I'm trying to enable you running the commands with the keyword convert
globally instead of a user having to be in the project directory and run cargo run <args>
or ./main <args>
.
My Cargo.toml
looks like this:
[package]
name = "converter_cli"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
[[bin]]
name = "convert"
path = "src/main.rs"
Currently, after some research, I've written these instructions which work for my computer (Mac M1):
- Make sure you have Rust installed on your system. If you don't, use this link.
- Clone the repo:
git clone https://github.com/mattrltrent/base_converter
. - In the project directory, run
cargo build --release
. - In the project directory, run
cargo install --path .
(don't miss the ending.
). - You should now be able to run the tool globally. To be sure, check if you can run
convert version
.
However, I've ran these instructions on a Windows PC and I get the error "Invalid drive specification", when trying to run convert <args>
.
Is there a better way to make this distributable (without publishing it as a Cargo crate) for Linux, Windows, and MacOS in one unified way? Or if not, why don't these instructions work for Windows?
If relevant, my file structure is as follows:
assets
-> <random image assets>
src
-> conversions.rs
-> errors.rs
-> main.rs
target
.gitignore
Cargo.lock
Cargo.toml
README.md
答案1
得分: 1
以下是翻译好的内容:
命名问题
名称被系统内置的名称所掩盖:
convert
已经是一个有效的命令:
> 将磁盘从一种磁盘类型转换为另一种磁盘类型。
>
> - https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/convert
以下是一些解决方案:
- 通过完整路径引用您的应用程序(可能不太美观,但应该可行)
- 在Windows上专门为您的应用程序创建别名
- 将您的应用程序重命名为一个更加独特的名称
分发
分发是一个相当大的主题。
想一想您通常如何安装新软件。行为不仅因人而异,还因所使用的操作系统、用户的限制(管理员权限)而异...
提供已编译的程序
(如@PaulDempsey已建议的)
(通常大多数人都习惯这种方式)
在哪里
- 作为GitHub上的发布
- 在专用网页上
- 在某个软件门户/应用商店上
如何
- 简单地提供二进制文件(即
*.exe
) - 打包在一个安装程序中
将您的软件包添加到软件包管理器存储库中
有许多软件包管理器可供考虑,以及将自己的应用程序放入其中的不同方法,例如:
- macOS 上的 brew
- Linux 上的 apt、pacman 等等
- Windows 上的 choco
- ...
其中一些可能会为您编译软件,而其他一些可能会简单地提供可执行文件。
将您的步骤转化为安装脚本
大多数步骤都可以轻松转化为shell和/或批处理脚本,以便用户只需运行 install.sh
,一切都正常运行。这样,您可以自动地在不同的系统上区分行为。
英文:
The naming issue
The name is overshadowed by system-builtin:
convert
is already a valid command:
> Converts a disk from one disk type to another.
>
> - https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/convert
Here are some solutions:
- Reference your application via full path (ugly, but should do the trick)
- Specifically alias your application on Windows
- Rename your application to a somewhat more unique name
Distributing
Distributing is quite a big topic.
Think about how you usually install new software. Behaviour differs from not only people but the used OS, restrictions of the user (admin rights), ...
Provide a compiled program
(as @PaulDempsey already suggested)
(in general most people are used to that)
where
- as release in GitHub
- on a dedicated webpage
- on some software portal / app store
how
- simply the binary (aka
*.exe
) - wrapped in an installer
Add your package to package manager repositories
there are a bunch of package managers to consider and there are different approaches to get ones own application in there but there are e.g.:
- brew for macOS
- apt, pacman and many more for Linux
- choco for Windows
- ...
Some of them might compile stuff for you others you might simply ship executables with.
Convert your steps into an install script
Most of your steps can easily be converted to a shell and/or batch script so the user can simply run install.sh
and everything is good to go. This way you can automatically differentiate behaviors on different systems.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论