Skip to content

Commit

Permalink
Fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
voidint committed Jan 5, 2018
2 parents 3276492 + e3564a9 commit f6d3c11
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 29 deletions.
46 changes: 26 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# tsdump
[![Build Status](https://travis-ci.org/voidint/tsdump.svg?branch=master)](https://travis-ci.org/voidint/tsdump)
[![Build Status](https://api.travis-ci.org/voidint/tsdump.png)](https://travis-ci.org/voidint/tsdump)
[![Coverage Status](https://coveralls.io/repos/github/voidint/tsdump/badge.svg?branch=master)](https://coveralls.io/github/voidint/tsdump?branch=master)

## 目录
Expand All @@ -20,27 +20,29 @@ $ go get -u github.com/voidint/tsdump
## 基本使用

```shell
$ tsdump --help
NAME:
tsdump - Database table structure dump tool.

USAGE:
tsdump [OPTIONS] [database [table ...]]

VERSION:
0.2.0
0.3.0

AUTHOR:
voidnt <[email protected]>

OPTIONS:
-D, --debug enable debug mode
-h value, --host value connect to host (default: "127.0.0.1")
-P value, --port value port number to use for connection (default: 3306)
-u value, --user value user for login if not current user (default: "voidint")
-V value, --viewer value output viewer. Optional values: txt|csv|json|md (default: "txt")
-o value, --output value write to a file, instead of STDOUT
--help show help
--version, -v print the version
-D, --debug enable debug mode
-h value, --host value connect to host (default: "127.0.0.1")
-P value, --port value port number to use for connection (default: 3306)
-u value, --user value user for login if not current user (default: "voidint")
-p value, --password value password to use when connecting to server. If password is not given it's solicited on the tty.
-V value, --viewer value output viewer. Optional values: txt|csv|json|md (default: "txt")
-o value, --output value write to a file, instead of STDOUT
--help show help
--version, -v print the version
COPYRIGHT:
Copyright (c) 2017, 2018, voidint. All rights reserved.
Expand Down Expand Up @@ -126,23 +128,27 @@ COPYRIGHT:
- 将用户权限范围内数据库及其表结构数据输出到csv文件
```shell
$ tsdump -h 127.0.0.1 -P 3307 -u root -V csv -o ./mydb.csv
$ tsdump -h 127.0.0.1 -P 3307 -u root -V csv > ./mydb.csv
```
- 将目标数据库及其所有表的表结构数据输出到JSON文件
```shell
$ tsdump -h 127.0.0.1 -P 3307 -u root -V json -o mydb.json mydb
$ tsdump -h 127.0.0.1 -P 3307 -u root -V json mydb > mydb.json
```
## Changelog
### 0.3.0 - 2018/01/05
- `Add feature`: 支持通过`-p`选项指定数据库登录密码。[#16](https://github.com/voidint/tsdump/issues/16)
- `Fixbug`: 标准输出重定向后获得的内容中包含有`Enter Password:`字样。[#17](https://github.com/voidint/tsdump/issues/17)
### 0.2.0 - 2018/01/01
- 支持从stdin console中读取数据库登录密码。[#5](https://github.com/voidint/tsdump/issues/5)
- 修正help信息。[#6](https://github.com/voidint/tsdump/issues/6)
- 支持命令行参数指定目标数据库和表。[#12](https://github.com/voidint/tsdump/issues/12)
- 支持通过`-h`选项指定主机名。[#14](https://github.com/voidint/tsdump/issues/14)
- `Add feature`: 支持从stdin console中读取数据库登录密码。[#5](https://github.com/voidint/tsdump/issues/5)
- `Fixbug`: 修正help信息。[#6](https://github.com/voidint/tsdump/issues/6)
- `Add feature`: 支持命令行参数指定目标数据库和表。[#12](https://github.com/voidint/tsdump/issues/12)
- `Add feature`: 支持通过`-h`选项指定主机名。[#14](https://github.com/voidint/tsdump/issues/14)
### 0.1.0 - 2017/12/31
- 支持以`csv`视图方式导出表结构数据。[#1](https://github.com/voidint/tsdump/issues/1)
- 支持以`markdown`视图方式导出表结构数据。[#2](https://github.com/voidint/tsdump/issues/2)
- 支持以`text`视图方式导出表结构数据。[#3](https://github.com/voidint/tsdump/issues/3)
- 支持以`json`视图方式导出表结构数据。[#4](https://github.com/voidint/tsdump/issues/4)
- `Add feature`: 支持以`csv`视图方式导出表结构数据。[#1](https://github.com/voidint/tsdump/issues/1)
- `Add feature`: 支持以`markdown`视图方式导出表结构数据。[#2](https://github.com/voidint/tsdump/issues/2)
- `Add feature`: 支持以`text`视图方式导出表结构数据。[#3](https://github.com/voidint/tsdump/issues/3)
- `Add feature`: 支持以`json`视图方式导出表结构数据。[#4](https://github.com/voidint/tsdump/issues/4)
26 changes: 17 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
_ "github.com/voidint/tsdump/view/txt"
)

const shortVersion = "0.2.0"
const shortVersion = "0.3.0"

var (
username string
Expand Down Expand Up @@ -103,6 +103,11 @@ func main() {
Usage: "user for login if not current user",
Destination: &c.Username,
},
cli.StringFlag{
Name: "p, password",
Usage: "password to use when connecting to server. If password is not given it's solicited on the tty.",
Destination: &c.Password,
},
cli.StringFlag{
Name: "V, viewer",
Value: txt.Name,
Expand All @@ -125,11 +130,11 @@ func main() {
c.Tables = args.Tail()
}

var passwd []byte
if passwd, err = readPassword(); err != nil {
return cli.NewExitError(fmt.Sprintf("[tsdump] %s", err.Error()), 1)
if c.Password == "" {
if c.Password, err = readPassword("Enter Password: "); err != nil {
return cli.NewExitError(fmt.Sprintf("[tsdump] %s", err.Error()), 1)
}
}
c.Password = string(passwd)
return nil
}

Expand Down Expand Up @@ -172,10 +177,13 @@ func main() {
}

// readPassword 从stdin读取密码
func readPassword() (passwd []byte, err error) {
defer fmt.Println()
fmt.Print("Enter Password: ")
return terminal.ReadPassword(int(os.Stdin.Fd()))
func readPassword(prompt string) (passwd string, err error) {
state, err := terminal.MakeRaw(int(os.Stdin.Fd()))
if err != nil {
return "", err
}
defer terminal.Restore(int(os.Stdin.Fd()), state)
return terminal.NewTerminal(os.Stdin, "").ReadPassword(prompt)
}

// getMetadata 根据目标数据库名和表名,返回目标数据库及其表的元数据。
Expand Down

0 comments on commit f6d3c11

Please sign in to comment.