Skip to content

Commit

Permalink
refactor(BREAKING CHANGE): Change the '-i' flag to familiar with ssh
Browse files Browse the repository at this point in the history
  • Loading branch information
vimiix committed Nov 14, 2024
1 parent 3eb3445 commit 617a3f2
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 31 deletions.
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<p align="center">
<img src="https://raw.githubusercontent.com/vimiix/ssx/master/static/demo.svg?sanitize=true"
height="500">
</p>

## Document

👉 [https://ssx.vimiix.com/](https://ssx.vimiix.com/)
Expand All @@ -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.
Expand Down Expand Up @@ -84,7 +79,7 @@ ssx list
### Tag an entry

```bash
ssx tag -i <ENTRY_ID> [-t TAG1 [-t TAG2 ...]] [-d TAG3 [-d TAG4 ...]]
ssx tag --id <ENTRY_ID> [-t TAG1 [-t TAG2 ...]] [-d TAG3 [-d TAG4 ...]]
```
Once we tag the entry, we can log in through the tag later.
Expand All @@ -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 <ID>
ssx --id <ID>
# login by address, support partial words
ssx <ADDRESS>
Expand All @@ -120,7 +115,7 @@ ssx 1.100 pwd
### Delete an entry
```bash
ssx delete -i <ENTRY_ID>
ssx delete --id <ENTRY_ID>
```
## Supported environment variables
Expand Down
17 changes: 6 additions & 11 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@

它会自动记住通过它登录的服务器,因此,当您再次登录时,无需再次输入密码。

<p align="center">
<img src="https://raw.githubusercontent.com/vimiix/ssx/master/static/demo.svg?sanitize=true"
height="500">
</p>

## 在线文档

👉 [https://ssx.vimiix.com/](https://ssx.vimiix.com/)
Expand All @@ -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 <ip>`
在这个命令中,`USER` 是可以省略的,如果省略则是系统当前用户名;`PORT` 是可以省略的,默认是 `22``-i IDENTITY_FILE` 代表的是使用私钥登录,通过 `-i` 来指定私钥的路径,也是可以省略的,默认是 `~/.ssh/id_rsa`,当然了,前提是这个文件存在。所以精简后的登录命令就是:`ssx <ip>`

当首次登录,不存在可用私钥时,会通过交互方式来让用户输入密码,一旦登录成功,这个密码就会被 ssx 保存到本地的数据文件中 (默认为 **~/.ssx/db**, 可通过环境变量 `SSX_DB_PATH` 进行自定义),下次登录时,仍然执行 `ssx <ip>` 即可自动登录。

Expand Down Expand Up @@ -95,10 +90,10 @@ ssx 会给每个存储的服务器分配一个唯一的 `ID`,我们在打标
打标签需要通过 ssx 的 `tag` 子命令来完成,下面是 tag 命令的模式:

```bash
ssx tag -i <ENTRY_ID> [-t TAG1 [-t TAG2 ...]] [-d TAG3 [-d TAG4 ...]]
ssx tag --id <ENTRY_ID> [-t TAG1 [-t TAG2 ...]] [-d TAG3 [-d TAG4 ...]]
```
- -i 指定 list 命令输出的要操作的服务器对应的 ID 字段
- --id 指定 list 命令输出的要操作的服务器对应的 ID 字段
- -t 指定要添加的标签名,可以多次指定就可以同时添加多个标签
- -d 打标签的同时也支持删除已有标签,通过 -d 指定要删除的标签名,同样也可以多次指定
Expand All @@ -117,7 +112,7 @@ ssx centos
ssx

# 按条目id登录
ssx -i <ID>
ssx --id <ID>

# 通过地址登录,支持部分单词
ssx <ADDRESS>
Expand All @@ -143,7 +138,7 @@ ssx centos [-c] pwd
### 删除服务器条目
```bash
ssx delete -i <ENTRY_ID>
ssx delete --id <ENTRY_ID>
```
## 支持的环境变量
Expand Down
4 changes: 2 additions & 2 deletions cmd/ssx/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion cmd/ssx/cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
8 changes: 4 additions & 4 deletions cmd/ssx/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions cmd/ssx/cmd/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ENTRY_ID> [-t TAG1 [-t TAG2 ...]] [-d TAG3 [-d TAG4 ...]]",
Example: "ssx tag --id <ENTRY_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")
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion cmd/ssx/cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions docs/zh-cn/release-notes.md
Original file line number Diff line number Diff line change
@@ -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日
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.4.3
v0.5.0

0 comments on commit 617a3f2

Please sign in to comment.