Skip to content

Commit 2d6134a

Browse files
authored
Merge pull request #210 from qiniu/develop
v2.3.5
2 parents e1f49fa + 0e5b0b2 commit 2d6134a

File tree

17 files changed

+629
-88
lines changed

17 files changed

+629
-88
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
# 2.3.5
2+
1. 增加token命令,创建Qbox token, qiniuToken, uploadToken
3+
2. qshell配置文件支持设置accessKey和secretKey
4+
3. 增加了arm版本
5+
4. listbucket2增加文件大小的可读性,可以使用Bytes, KB, MB, GB格式显示
6+
17
# 2.3.4
2-
1. listbucket, listbucket2增加捕捉interrupt信号(CTR-C), 打印marker
8+
1. listbucket2增加捕捉interrupt信号(CTR-C), 打印marker
39
2. account在本地记录账号,默认不覆盖, 加了-w强制覆盖选项
410
3. listbucket2 增加append 模式(-a)开启, 修复列举几亿空间的时候,列举一半左右程序中断问题
511
4. 修复dircache 列表没有输出到文件使用-o选项的时候

Makefile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@ WIN64=qshell_windows_x64.exe
33
DARWIN=qshell_darwin_x64
44
LINUX86=qshell_linux_x86
55
LINUX64=qshell_linux_x64
6+
LINUXARM=qshell_linux_arm
67

78
install:
89
GOOS=darwin GOARCH=amd64 go build -o $(DARWIN) .
910
cp ./$(DARWIN) /usr/local/bin/qshell && rm ./$(DARWIN)
1011

11-
all:
12-
GOOS=windows GOARCH=386 go build -o $(WIN86) .
13-
GOOS=windows GOARCH=amd64 go build -o $(WIN64) .
14-
GOOS=darwin GOARCH=amd64 go build -o $(DARWIN) .
15-
GOOS=linux GOARCH=386 go build -o $(LINUX86) .
16-
GOOS=linux GOARCH=amd64 go build -o $(LINUX64) .
12+
all: linux windows arm
1713

1814
linux:
1915
GOOS=linux GOARCH=386 go build -o $(LINUX86) .
@@ -22,3 +18,6 @@ linux:
2218
windows:
2319
GOOS=windows GOARCH=386 go build -o $(WIN86) .
2420
GOOS=windows GOARCH=amd64 go build -o $(WIN64) .
21+
22+
arm:
23+
GOOS=linux GOARCH=arm go build -o $(LINUXARM)

README.md

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ qshell是利用[七牛文档上公开的API](http://developer.qiniu.com)实现
1212
1313
|版本 |支持平台|链接|
1414
|--------|---------|----|
15-
|qshell-v2.3.4 |Mac OSX, Linux, Windows|[下载](http://devtools.qiniu.com/qshell-v2.3.4.zip)|
15+
|qshell-v2.3.5 |Mac OSX, Linux, Windows|[下载](http://devtools.qiniu.com/qshell-v2.3.5.zip)|
1616

1717
## 安装
1818

@@ -72,14 +72,29 @@ $ qshell account -- <Your AccessKey> <Your SecretKey> <Your Name>
7272
可以连续使用qshell account 添加账号ak, sk, name信息,qshell会保存这些账号的信息, 可以使用qshell user命令列举账号信息,在各个账号之间切换, 删除账号等。
7373
如果使用的2.3.0之前的版本account命令记录的账户信息,需要先使用qshell user clean清楚保存的账户信息,然后使用qshell account命令重新记录账户信息。
7474

75+
也可以使用qshell的配置文件添加access_key和secret_key信息,具体配置方法参考下面配置文件一节。
76+
7577
2. 添加完账户后,就可以使用qshell上传,下载文件了
7678

7779
## 账户管理
7880

81+
qshell支持多种方式的账户管理:
82+
1. 使用qshell account <AccessKey> <SecretKey> <Name>记录账户信息到本地的数据库
83+
2. 使用qshell -C <ConfigFile> 配置文件的方式来设置账户信息
84+
3. 有的qshell子命令支持通过--access-key, --secret-key选项来设置ak/sk信息
85+
86+
那么有可能上面三种方式都提供了账户的信息,因此这三种方式有个优先级(从高到低):
87+
3 > 2 > 1
88+
89+
也就是说,如果命令行提供了ak/sk那么使用命令行的信息;如果没有提供就使用配置文件中的信息,如果配置文件没有提供ak/sk, 那么会去本地数据库查找当前的用户。
90+
7991
使用qshell user子命令可以用来管理记录的多账户信息。
8092
1. qshell user ls可以列举账户下所有的账户信息
8193
2. qshell user cu <userName>可以用来切换账户
8294
3. qshell user cu 不携带<userName>的话会切换到最近的上个账户;比如我在A账户做完操作后,使用qshell user cu B到了B 账户,那么使用qshell user cu可以切回到A账户.
95+
4. qshell user lookup <userName> 查找用户是否在本地数据库中
96+
97+
<userName>是使用qshell account <AK> <SK> <Name>记录的时候的<Name>名字,这个名字可以任意指定。
8398

8499
## 开启命令的自动补全
85100
**linux上,使用bash**
@@ -130,16 +145,17 @@ fi
130145

131146
1. 配置文件格式支持json, 如果需要使用配置文件,需要在家目录下创建文件名为.qshell.json的json文件
132147
2. 配置文件可以配置如io host, api host, rs hsot, rsf host, 这些如果没有指定,程序会自动选择
148+
3. 配置文件支持设置ak, sk
133149

134150
例子:
135151

136-
默认官方的列举空间的文件使用的是rs.qiniu.com域名,如果因为某种原因,比如私有存储,需要替换使用rs-test.qiniu.com这个域名的话,那么只需要
152+
1. 默认官方的列举空间的文件使用的是rs.qiniu.com域名,如果因为某种原因,比如私有存储,需要替换使用rs-test.qiniu.com这个域名的话,那么只需要
137153
在家目录下创建文件名字为.qshell.json的配置文件,文件内容为
138154

139155
```json
140156
{
141157
"hosts": {
142-
"rs_host": "rs-test.qiniu.com"
158+
"rs": "rs-test.qiniu.com"
143159
}
144160
}
145161
```
@@ -149,8 +165,8 @@ fi
149165
```json
150166
{
151167
"hosts": {
152-
"rs_host": "rs-test.qiniu.com",
153-
"io_host": "io-test.qiniu.com"
168+
"rs": "rs-test.qiniu.com",
169+
"io": "io-test.qiniu.com"
154170
}
155171
}
156172
```
@@ -160,14 +176,25 @@ fi
160176
```json
161177
{
162178
"hosts": {
163-
"rs_host": "rs-test.qiniu.com",
164-
"io_host": "io-test.qiniu.com",
165-
"api_host": "",
166-
"rsf_host": ""
179+
"rs": "rs-test.qiniu.com",
180+
"io": "io-test.qiniu.com",
181+
"api": "",
182+
"rsf": ""
167183
}
168184
}
169185
```
170186

187+
2. 如果不想使用qshell account ak sk name的方式记录密钥信息,也可以在配置文件中指定ak, sk
188+
189+
```json
190+
{
191+
"access_key": "",
192+
"secret_key": "",
193+
}
194+
```
195+
196+
这样qshell会优先使用配置文件中配置的ak/sk信息,如果在这个配置文件中没有找到密钥信息,那么会去qshell account记录的本地数据库寻找.
197+
171198

172199
## 命令列表
173200

cmd/putfile.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/qiniu/api.v7/storage"
77
"github.com/qiniu/qshell/iqshell"
88
"github.com/spf13/cobra"
9-
"github.com/spf13/viper"
109
"os"
1110
"strings"
1211
"time"
@@ -23,7 +22,8 @@ var (
2322
mimeType string
2423
fileType int
2524
workerCount int
26-
upHost string
25+
rupHost string
26+
fupHost string
2727
callbackUrls string
2828
callbackHost string
2929
)
@@ -47,21 +47,18 @@ func init() {
4747
formPutCmd.Flags().StringVarP(&mimeType, "mimetype", "t", "", "file mime type")
4848
formPutCmd.Flags().IntVarP(&fileType, "storage", "s", 0, "storage type")
4949
formPutCmd.Flags().IntVarP(&workerCount, "worker", "c", 16, "worker count")
50-
formPutCmd.Flags().StringVarP(&upHost, "up-host", "u", "", "uphost")
50+
formPutCmd.Flags().StringVarP(&fupHost, "up-host", "u", "", "uphost")
5151
formPutCmd.Flags().StringVarP(&callbackUrls, "callback-urls", "l", "", "upload callback urls, separated by comma")
5252
formPutCmd.Flags().StringVarP(&callbackHost, "callback-host", "T", "", "upload callback host")
5353

5454
RePutCmd.Flags().BoolVarP(&pOverwrite, "overwrite", "w", false, "overwrite mode")
5555
RePutCmd.Flags().StringVarP(&mimeType, "mimetype", "t", "", "file mime type")
5656
RePutCmd.Flags().IntVarP(&fileType, "storage", "s", 0, "storage type")
5757
RePutCmd.Flags().IntVarP(&workerCount, "worker", "c", 16, "worker count")
58-
RePutCmd.Flags().StringVarP(&upHost, "up-host", "u", "", "uphost")
58+
RePutCmd.Flags().StringVarP(&rupHost, "up-host", "u", "", "uphost")
5959
RePutCmd.Flags().StringVarP(&callbackUrls, "callback-urls", "l", "", "upload callback urls, separated by comma")
6060
RePutCmd.Flags().StringVarP(&callbackHost, "callback-host", "T", "", "upload callback host")
6161

62-
viper.BindPFlag("hosts.up_host", formPutCmd.Flags().Lookup("up-host"))
63-
viper.BindPFlag("hosts.up_host", RePutCmd.Flags().Lookup("up-host"))
64-
6562
RootCmd.AddCommand(formPutCmd, RePutCmd)
6663
}
6764

@@ -105,16 +102,16 @@ func FormPut(cmd *cobra.Command, params []string) {
105102
}
106103

107104
var putExtra storage.PutExtra
105+
var upHost string
108106

109-
if upHost != "" {
110-
if !strings.HasPrefix(upHost, "http") {
111-
upHost = "http://" + upHost
112-
}
113-
putExtra = storage.PutExtra{
114-
UpHost: upHost,
115-
}
107+
if fupHost == "" {
108+
upHost = iqshell.UpHost()
109+
} else {
110+
upHost = fupHost
111+
}
112+
putExtra = storage.PutExtra{
113+
UpHost: upHost,
116114
}
117-
118115
if mimeType != "" {
119116
putExtra.MimeType = mimeType
120117
}
@@ -223,13 +220,15 @@ func ResumablePut(cmd *cobra.Command, params []string) {
223220
}
224221

225222
var putExtra storage.RputExtra
226-
if upHost != "" {
227-
if !strings.HasPrefix(upHost, "http") {
228-
upHost = "http://" + upHost
229-
}
230-
putExtra = storage.RputExtra{
231-
UpHost: upHost,
232-
}
223+
var upHost string
224+
225+
if rupHost == "" {
226+
upHost = iqshell.UpHost()
227+
} else {
228+
upHost = rupHost
229+
}
230+
putExtra = storage.RputExtra{
231+
UpHost: upHost,
233232
}
234233
if mimeType != "" {
235234
putExtra.MimeType = mimeType
@@ -250,6 +249,7 @@ func ResumablePut(cmd *cobra.Command, params []string) {
250249

251250
resume_uploader := storage.NewResumeUploader(nil)
252251
err = resume_uploader.PutFile(context.Background(), &putRet, uptoken, key, localFile, &putExtra)
252+
253253
fmt.Println()
254254
if err != nil {
255255
if v, ok := err.(*storage.ErrorInfo); ok {

cmd/root.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import (
44
"fmt"
55
"github.com/astaxie/beego/logs"
66
"github.com/qiniu/api.v7/storage"
7+
"github.com/qiniu/qshell/iqshell"
78
"github.com/spf13/cobra"
89
"github.com/spf13/viper"
910
"os"
1011
"os/user"
1112
"path/filepath"
1213
"runtime"
14+
"strings"
1315
)
1416

1517
var (
@@ -76,11 +78,21 @@ func initConfig() {
7678
storage.UserAgent = UserAgent()
7779

7880
//parse command
79-
logs.SetLevel(logs.LevelInformational)
81+
if DebugFlag {
82+
logs.SetLevel(logs.LevelDebug)
83+
} else {
84+
logs.SetLevel(logs.LevelInformational)
85+
}
8086
logs.SetLogger(logs.AdapterConsole)
8187

88+
var jsonConfigFile string
89+
8290
if cfgFile != "" {
83-
viper.SetConfigFile(cfgFile)
91+
if !strings.HasSuffix(cfgFile, ".json") {
92+
jsonConfigFile = cfgFile + ".json"
93+
os.Rename(cfgFile, jsonConfigFile)
94+
}
95+
viper.SetConfigFile(jsonConfigFile)
8496
} else {
8597
curUser, gErr := user.Current()
8698
if gErr != nil {
@@ -97,28 +109,28 @@ func initConfig() {
97109
fmt.Fprintf(os.Stderr, "get current directory: %v\n", gErr)
98110
os.Exit(1)
99111
}
100-
viper.Set("path.root_path", dir+"/.qshell")
112+
iqshell.SetRootPath(dir + "/.qshell")
101113
} else {
102114
curUser, gErr := user.Current()
103115
if gErr != nil {
104116
fmt.Fprintf(os.Stderr, "Error: get current user error: %v\n", gErr)
105117
os.Exit(1)
106118
}
107-
viper.Set("path.root_path", curUser.HomeDir+"/.qshell")
119+
iqshell.SetRootPath(curUser.HomeDir + "/.qshell")
108120
}
109-
rootPath := viper.GetString("path.root_path")
121+
rootPath := iqshell.RootPath()
110122

111-
viper.SetDefault("path.acc_db_path", filepath.Join(rootPath, "account.db"))
112-
viper.SetDefault("path.acc_path", filepath.Join(rootPath, "account.json"))
113-
viper.SetDefault("hosts.up_host", "upload.qiniup.com")
114-
viper.SetDefault("hosts.rs_host", storage.DefaultRsHost)
115-
viper.SetDefault("hosts.rsf_host", storage.DefaultRsfHost)
116-
viper.SetDefault("hosts.io_host", "iovip.qbox.me")
117-
viper.SetDefault("hosts.api_host", storage.DefaultAPIHost)
123+
iqshell.SetDefaultAccDBPath(filepath.Join(rootPath, "account.db"))
124+
iqshell.SetDefaultAccPath(filepath.Join(rootPath, "account.json"))
125+
iqshell.SetDefaultRsHost(storage.DefaultRsHost)
126+
iqshell.SetDefaultRsfHost(storage.DefaultRsfHost)
127+
iqshell.SetDefaultIoHost("iovip.qbox.me")
128+
iqshell.SetDefaultApiHost(storage.DefaultAPIHost)
118129

119130
if rErr := viper.ReadInConfig(); rErr != nil {
120131
if _, ok := rErr.(viper.ConfigFileNotFoundError); !ok {
121132
fmt.Fprintf(os.Stderr, "read config file: %v\n", rErr)
122133
}
123134
}
135+
os.Rename(jsonConfigFile, cfgFile)
124136
}

cmd/rs.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ var (
132132
maxRetry int
133133
finalKey string
134134
appendMode bool
135+
readable bool
135136
)
136137

137138
func init() {
@@ -150,6 +151,7 @@ func init() {
150151
lsBucketCmd2.Flags().StringVarP(&startDate, "start", "s", "", "start date with format yyyy-mm-dd-hh-MM-ss")
151152
lsBucketCmd2.Flags().StringVarP(&endDate, "end", "e", "", "end date with format yyyy-mm-dd-hh-MM-ss")
152153
lsBucketCmd2.Flags().BoolVarP(&appendMode, "append", "a", false, "append to file")
154+
lsBucketCmd2.Flags().BoolVarP(&readable, "readable", "r", false, "present file size with human readable format")
153155

154156
moveCmd.Flags().BoolVarP(&mOverwrite, "overwrite", "w", false, "overwrite mode")
155157
moveCmd.Flags().StringVarP(&finalKey, "key", "k", "", "filename saved in bucket")
@@ -218,7 +220,7 @@ func ListBucket2(cmd *cobra.Command, params []string) {
218220
}
219221
}
220222
bm := iqshell.GetBucketManager()
221-
retErr := bm.ListBucket2(bucket, prefix, listMarker, outFile, "", start, end, sf, maxRetry, appendMode)
223+
retErr := bm.ListBucket2(bucket, prefix, listMarker, outFile, "", start, end, sf, maxRetry, appendMode, readable)
222224
if retErr != nil {
223225
os.Exit(iqshell.STATUS_ERROR)
224226
}

0 commit comments

Comments
 (0)