-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,058 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package cmd | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/qiniu/qshell/v2/docs" | ||
"github.com/qiniu/qshell/v2/iqshell" | ||
"github.com/qiniu/qshell/v2/iqshell/storage/object/operations" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var createShareCmdBuilder = func(cfg *iqshell.Config) *cobra.Command { | ||
var info = operations.CreateShareInfo{} | ||
var cmd = &cobra.Command{ | ||
Use: "create-share [kodo://]<Bucket>/<Prefix>", | ||
Short: "Share the specified directory", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cfg.CmdCfg.CmdId = docs.CreateShareType | ||
if len(args) > 0 { | ||
url := args[0] | ||
url = strings.TrimPrefix(url, "kodo://") | ||
parts := strings.SplitN(url, "/", 2) | ||
if len(parts) > 0 { | ||
info.Bucket = parts[0] | ||
} | ||
if len(parts) > 1 { | ||
info.Prefix = parts[1] | ||
} | ||
info.Permission = "READONLY" | ||
} | ||
operations.CreateShare(cfg, info) | ||
}, | ||
} | ||
cmd.Flags().StringVarP(&info.ExtractCode, "extract-code", "", "", "Specify extract code for the share, must consist of 6 alphabets and numbers") | ||
cmd.Flags().Int64VarP(&info.DurationSeconds, "validity-period", "", 900, "Specify validity period in seconds, must be longer than 1 mintutes and shorter than 2 hours") | ||
cmd.Flags().StringVarP(&info.OutputPath, "output", "", "", "Specify path to save output") | ||
return cmd | ||
} | ||
|
||
var listShareCmdBuilder = func(cfg *iqshell.Config) *cobra.Command { | ||
var info = operations.ListShareInfo{} | ||
var cmd = &cobra.Command{ | ||
Use: "share-ls <Link>", | ||
Short: "List shared files", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cfg.CmdCfg.CmdId = docs.ShareLsType | ||
if len(args) > 0 { | ||
info.LinkURL = args[0] | ||
} | ||
operations.ListShare(cfg, info) | ||
}, | ||
} | ||
cmd.Flags().StringVarP(&info.ExtractCode, "extract-code", "", "", "Specify extract code for the share, must consist of 6 alphabets and numbers") | ||
cmd.Flags().StringVarP(&info.Prefix, "prefix", "p", "", "list the shared directory with this prefix if set") | ||
cmd.Flags().Int64VarP(&info.Limit, "limit", "n", 0, "max count of items to output") | ||
cmd.Flags().StringVarP(&info.Marker, "marker", "m", "", "list marker") | ||
return cmd | ||
} | ||
|
||
var copyShareCmdBuilder = func(cfg *iqshell.Config) *cobra.Command { | ||
var info = operations.CopyShareInfo{} | ||
var cmd = &cobra.Command{ | ||
Use: "share-cp <Link> --to=<ToPath>", | ||
Short: "Copy shared files", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cfg.CmdCfg.CmdId = docs.ShareCpType | ||
if len(args) > 0 { | ||
info.LinkURL = args[0] | ||
} | ||
operations.CopyShare(cfg, info) | ||
}, | ||
} | ||
cmd.Flags().StringVarP(&info.ExtractCode, "extract-code", "", "", "Specify extract code for the share, must consist of 6 alphabets and numbers") | ||
cmd.Flags().StringVarP(&info.FromPath, "from", "", "", "copy from path") | ||
cmd.Flags().StringVarP(&info.ToPath, "to", "", "", "copy to path") | ||
cmd.Flags().BoolVarP(&info.Recursive, "recursive", "r", false, "copy directories recursively") | ||
return cmd | ||
} | ||
|
||
func init() { | ||
registerLoader(shareCmdLoader) | ||
} | ||
|
||
func shareCmdLoader(superCmd *cobra.Command, cfg *iqshell.Config) { | ||
superCmd.AddCommand( | ||
createShareCmdBuilder(cfg), | ||
listShareCmdBuilder(cfg), | ||
copyShareCmdBuilder(cfg), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package docs | ||
|
||
import _ "embed" | ||
|
||
//go:embed create-share.md | ||
var createShareDocument string | ||
|
||
const CreateShareType = "create-share" | ||
|
||
func init() { | ||
addCmdDocumentInfo(CreateShareType, createShareDocument) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# 简介 | ||
`create-share` 命令为需要分享的目录创建授权链接。 | ||
|
||
# 格式 | ||
``` | ||
qshell create-share [kodo://]<Bucket>/<Prefix> | ||
``` | ||
|
||
# 帮助文档 | ||
可以在命令行输入如下命令获取帮助文档: | ||
``` | ||
// 简单描述 | ||
$ qshell create-share -h | ||
// 详细文档(此文档) | ||
$ qshell create-share --doc | ||
``` | ||
|
||
# 鉴权 | ||
需要使用 `qshell account` 或者 `qshell user add` 命令设置鉴权信息 `AccessKey`, `SecretKey` 和 `Name`。 | ||
|
||
# 参数 | ||
- Bucket: 空间名称【必选】 | ||
- Prefix: 前缀【必选】 | ||
|
||
# 选项 | ||
- --extract-code: 提取码,只能包含六位大小写字母或者数字,如果不填写,将会自动生成。【可选】 | ||
- --validity-period: 有效时间,如果不填写,默认为 15 分钟。【可选】 | ||
- --output: 保存路径,以 JSON 格式保存输出内容,如果不填写,则直接以文本形式输出。【可选】 | ||
|
||
# 示例 | ||
``` | ||
$ qshell create-share kodo://bucketname/prefix | ||
Link: | ||
http://portal.qiniu.com/kodo-shares/verify?id=AGQEKDRxBBjbGmsKduQS9oFx59rz&token=qhtbC5YmDCO-WiPriuoCG_t4hZ1LboSOtRYSJXo_%3A9uJY8FiNrKjNrt4MpBx547jlgwr8aes15z5i8VY6l5SU6ga2IKWDBSGTv1jo-rOocklE7QqApzG6okJktZ36umLoqv9x1kuo5fNmgasLXowyTuHIM3kXsaV_DoXmvQsGr5ol6j4RtrmLcKdtXhpkGH8MfSjEgRV91Bx_Q_mSwpJ1028p8yZCSad_QOu_kSPxzeLZmWlUpAtO2oEXdbMTBxhTCH_3awCgqkgoogi0FQGP4zHxeFr0n3vj69DpmWqe6DiYbYLivCuU0kOF5Khv4I6-w6vjjdY | ||
Extract Code: | ||
wp7gqc | ||
Expire: | ||
2024-10-09 10:44:41 +0000 | ||
$ qshell create-share --output=share.json kodo://bucketname/prefix | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.