From 617a3f2b8177555195798fadd61e9d196db8ad7e Mon Sep 17 00:00:00 2001 From: vimiix Date: Thu, 14 Nov 2024 09:21:24 +0800 Subject: [PATCH] refactor(BREAKING CHANGE): Change the '-i' flag to familiar with ssh --- README.md | 13 ++++--------- README_zh.md | 17 ++++++----------- cmd/ssx/cmd/delete.go | 4 ++-- cmd/ssx/cmd/info.go | 2 +- cmd/ssx/cmd/root.go | 8 ++++---- cmd/ssx/cmd/tag.go | 4 ++-- cmd/ssx/cmd/upgrade.go | 2 +- docs/zh-cn/release-notes.md | 25 +++++++++++++++++++++++++ version | 2 +- 9 files changed, 46 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 73f009d..3f1ef4e 100644 --- a/README.md +++ b/README.md @@ -21,11 +21,6 @@ It will automatically remember the server which login through it, so you do not need to enter the password again when you log in again. -

- -

- ## Document 👉 [https://ssx.vimiix.com/](https://ssx.vimiix.com/) @@ -47,7 +42,7 @@ then you can get ssx binary in **dist** directory. ### Add a new entry ```bash -ssx [USER@]HOST[:PORT] [-k IDENTITY_FILE] [-p PORT] +ssx [USER@]HOST[:PORT] [-i IDENTITY_FILE] [-p PORT] ``` If given address matched an exist entry, ssx will login directly. @@ -84,7 +79,7 @@ ssx list ### Tag an entry ```bash -ssx tag -i [-t TAG1 [-t TAG2 ...]] [-d TAG3 [-d TAG4 ...]] +ssx tag --id [-t TAG1 [-t TAG2 ...]] [-d TAG3 [-d TAG4 ...]] ``` Once we tag the entry, we can log in through the tag later. @@ -98,7 +93,7 @@ If not specified any flag, ssx will treat the second argument as a keyword for s ssx # login by entry id -ssx -i +ssx --id # login by address, support partial words ssx
@@ -120,7 +115,7 @@ ssx 1.100 pwd ### Delete an entry ```bash -ssx delete -i +ssx delete --id ``` ## Supported environment variables diff --git a/README_zh.md b/README_zh.md index 2b4ba0d..e3033ca 100644 --- a/README_zh.md +++ b/README_zh.md @@ -21,11 +21,6 @@ 它会自动记住通过它登录的服务器,因此,当您再次登录时,无需再次输入密码。 -

- -

- ## 在线文档 👉 [https://ssx.vimiix.com/](https://ssx.vimiix.com/) @@ -47,12 +42,12 @@ make ssx ### 添加新条目(登录一次即代表新增) ```bash -ssx [USER@]HOST[:PORT] [-k IDENTITY_FILE] [-p PORT] +ssx [USER@]HOST[:PORT] [-i IDENTITY_FILE] [-p PORT] ``` > 如果给定的地址与一个存在的条目匹配,ssx 将直接登录。 -在这个命令中,`USER` 是可以省略的,如果省略则是系统当前用户名;`PORT` 是可以省略的,默认是 `22`,`-k IDENTITY_FILE` 代表的是使用私钥登录,通过 `-k` 来指定私钥的路径,也是可以省略的,默认是 `~/.ssh/id_rsa`,当然了,前提是这个文件存在。所以精简后的登录命令就是:`ssx ` +在这个命令中,`USER` 是可以省略的,如果省略则是系统当前用户名;`PORT` 是可以省略的,默认是 `22`,`-i IDENTITY_FILE` 代表的是使用私钥登录,通过 `-i` 来指定私钥的路径,也是可以省略的,默认是 `~/.ssh/id_rsa`,当然了,前提是这个文件存在。所以精简后的登录命令就是:`ssx ` 当首次登录,不存在可用私钥时,会通过交互方式来让用户输入密码,一旦登录成功,这个密码就会被 ssx 保存到本地的数据文件中 (默认为 **~/.ssx/db**, 可通过环境变量 `SSX_DB_PATH` 进行自定义),下次登录时,仍然执行 `ssx ` 即可自动登录。 @@ -95,10 +90,10 @@ ssx 会给每个存储的服务器分配一个唯一的 `ID`,我们在打标 打标签需要通过 ssx 的 `tag` 子命令来完成,下面是 tag 命令的模式: ```bash -ssx tag -i [-t TAG1 [-t TAG2 ...]] [-d TAG3 [-d TAG4 ...]] +ssx tag --id [-t TAG1 [-t TAG2 ...]] [-d TAG3 [-d TAG4 ...]] ``` -- -i 指定 list 命令输出的要操作的服务器对应的 ID 字段 +- --id 指定 list 命令输出的要操作的服务器对应的 ID 字段 - -t 指定要添加的标签名,可以多次指定就可以同时添加多个标签 - -d 打标签的同时也支持删除已有标签,通过 -d 指定要删除的标签名,同样也可以多次指定 @@ -117,7 +112,7 @@ ssx centos ssx # 按条目id登录 -ssx -i +ssx --id # 通过地址登录,支持部分单词 ssx
@@ -143,7 +138,7 @@ ssx centos [-c] pwd ### 删除服务器条目 ```bash -ssx delete -i +ssx delete --id ``` ## 支持的环境变量 diff --git a/cmd/ssx/cmd/delete.go b/cmd/ssx/cmd/delete.go index f6d58df..fca4b21 100644 --- a/cmd/ssx/cmd/delete.go +++ b/cmd/ssx/cmd/delete.go @@ -12,7 +12,7 @@ func newDeleteCmd() *cobra.Command { Use: "delete", Aliases: []string{"d", "del"}, Short: "delete entry by id", - Example: "ssx delete -i1 [-i2 ...]", + Example: "ssx delete --id 1 [--id 2 ...]", RunE: func(cmd *cobra.Command, args []string) error { if len(ids) == 0 { fmt.Println("no id specified, do nothing") @@ -21,6 +21,6 @@ func newDeleteCmd() *cobra.Command { return ssxInst.DeleteEntryByID(ids...) }, } - cmd.Flags().IntSliceVarP(&ids, "id", "i", nil, "entry id") + cmd.Flags().IntSliceVarP(&ids, "id", "", nil, "entry id") return cmd } diff --git a/cmd/ssx/cmd/info.go b/cmd/ssx/cmd/info.go index 2e99cdb..c028950 100644 --- a/cmd/ssx/cmd/info.go +++ b/cmd/ssx/cmd/info.go @@ -31,7 +31,7 @@ func newInfoCmd() *cobra.Command { fmt.Println(string(bs)) return nil }} - cmd.Flags().Uint64VarP(&opt.EntryID, "id", "i", 0, "entry id") + cmd.Flags().Uint64VarP(&opt.EntryID, "id", "", 0, "entry id") cmd.Flags().StringVarP(&opt.Addr, "server", "s", "", "target server address\nsupport formats: [user@]host[:port]") cmd.Flags().StringVarP(&opt.Tag, "tag", "t", "", "search entry by tag") diff --git a/cmd/ssx/cmd/root.go b/cmd/ssx/cmd/root.go index fbacf6a..6179c84 100644 --- a/cmd/ssx/cmd/root.go +++ b/cmd/ssx/cmd/root.go @@ -29,10 +29,10 @@ ssx [USER@]HOST[:PORT] # Login with proxy server ssx [-J PROXY_USER@PROXY_HOST:PROXY_PORT] [USER@]HOST[:PORT]] -# After login once, you can login directly with host or tag or specify ID with -i +# After login once, you can login directly with host or tag or specify ID with --id ssx [USER@]HOST[:PORT] ssx TAG_NAME -ssx -i ID +ssx --id ID # Fuzzy search is also supported # For example, you want to login to 192.168.1.100 and @@ -76,10 +76,10 @@ ssx 100 pwd`, }, } root.Flags().StringVarP(&opt.DBFile, "file", "f", "", "filepath to store auth data") - root.Flags().Uint64VarP(&opt.EntryID, "id", "i", 0, "entry id") + root.Flags().Uint64VarP(&opt.EntryID, "id", "", 0, "entry id") root.Flags().StringVarP(&opt.Addr, "server", "s", "", "target server address\nsupport format: [user@]host[:port]") root.Flags().StringVarP(&opt.Tag, "tag", "t", "", "search entry by tag") - root.Flags().StringVarP(&opt.IdentityFile, "keyfile", "k", "", "identity_file path") + root.Flags().StringVarP(&opt.IdentityFile, "identity-file", "i", "", "identity_file path") root.Flags().StringVarP(&opt.JumpServers, "jump-server", "J", "", "jump servers, multiple jump hops may be specified separated by comma characters\nformat: [user1@]host1[:port1][,[user2@]host2[:port2]...]") root.Flags().StringVarP(&opt.Command, "cmd", "c", "", "excute the command and exit") root.Flags().DurationVar(&opt.Timeout, "timeout", 0, "timeout for connecting and executing command") diff --git a/cmd/ssx/cmd/tag.go b/cmd/ssx/cmd/tag.go index d1da809..3248d94 100644 --- a/cmd/ssx/cmd/tag.go +++ b/cmd/ssx/cmd/tag.go @@ -15,7 +15,7 @@ func newTagCmd() *cobra.Command { Use: "tag", Aliases: []string{"t"}, Short: "add or delete tag for entry by id", - Example: "ssx tag -i [-t TAG1 [-t TAG2 ...]] [-d TAG3 [-d TAG4 ...]]", + Example: "ssx tag --id [-t TAG1 [-t TAG2 ...]] [-d TAG3 [-d TAG4 ...]]", RunE: func(cmd *cobra.Command, args []string) error { if len(appendtTags) == 0 && len(deleteTags) == 0 { return errors.New("no tag is spicified") @@ -34,7 +34,7 @@ func newTagCmd() *cobra.Command { }, } - cmd.Flags().IntVarP(&id, "id", "i", 0, "entry id") + cmd.Flags().IntVarP(&id, "id", "", 0, "entry id") cmd.Flags().StringSliceVarP(&appendtTags, "tag", "t", nil, "tag name to add") cmd.Flags().StringSliceVarP(&deleteTags, "delete", "d", nil, "tag name to delete") _ = cmd.MarkFlagRequired("id") diff --git a/cmd/ssx/cmd/upgrade.go b/cmd/ssx/cmd/upgrade.go index fb46efe..5390e62 100644 --- a/cmd/ssx/cmd/upgrade.go +++ b/cmd/ssx/cmd/upgrade.go @@ -112,7 +112,7 @@ func upgrade(ctx context.Context, opt *upgradeOpt) error { return err } // check version - lg.Info("LatestVersion: %s, NowVersion: %s", pkgInfo.Version, version.Version) + lg.Info("latest version: %s, current version: %s", pkgInfo.Version, version.Version) if pkgInfo.Version == version.Version { lg.Info("You are currently using the latest version.") return nil diff --git a/docs/zh-cn/release-notes.md b/docs/zh-cn/release-notes.md index 85a549c..baa6f90 100644 --- a/docs/zh-cn/release-notes.md +++ b/docs/zh-cn/release-notes.md @@ -1,5 +1,30 @@ # 发布日志 +## v0.5.0 + +发布时间:2024年11月14日 + +### BREAKING CHANGE + +- Changed the SSH identity file flag from `-k` to `-i` to be more compatible with the standard `ssh` command +- Changed the entry ID flag from `-i` to `--id` across all commands for consistency +- Updated command examples and help text to reflect the new flag names + +### Why + +- The `-i` flag is the standard flag for specifying identity files in SSH, making SSX more intuitive for users familiar with SSH +- Using `--id` for entry IDs makes the parameter name more descriptive and avoids conflict with the SSH identity file flag + +### Example Usage + +```text +Old: ssx delete -i 123 +New: ssx delete --id 123 + +Old: ssx -k ~/.ssh/id_rsa +New: ssx -i ~/.ssh/id_rsa +``` + ## v0.4.3 发布时间:2024年9月20日 diff --git a/version b/version index f87d474..b043aa6 100644 --- a/version +++ b/version @@ -1 +1 @@ -v0.4.3 +v0.5.0