代码拉取完成,页面将自动刷新
同步操作将从 开源中国/git-repo-clean 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package main
import (
"errors"
"fmt"
"os"
"regexp"
"strings"
"github.com/AlecAivazis/survey/v2"
"github.com/AlecAivazis/survey/v2/terminal"
)
var qs = []*survey.Question{
{
Name: "fileType",
Prompt: &survey.Input{
Message: LocalSprintf("select the type of file to scan, such as zip, png:"),
Default: DefaultFileType,
Help: LocalSprintf("default is all types. If you want to specify a type, you can directly enter the type suffix without prefix '.'"),
},
Validate: func(ans interface{}) error {
str, ok := ans.(string)
if !ok || len(str) > 50 {
return errors.New(LocalSprintf("filetype error one"))
}
match, _ := regexp.MatchString(`^[a-zA-Z1-9]+[.]?[a-zA-Z1-9]*$|^[a-zA-Z1-9]+$`, str)
if !match && str != DefaultFileType {
return errors.New(LocalSprintf("filetype error two"))
}
return nil
},
},
{
Name: "fileSize",
Prompt: &survey.Input{
Message: LocalSprintf("select the minimum size of the file to scan, such as 1m, 1G:"),
Default: "1M",
Help: LocalSprintf("the size value needs units, such as 10K. The optional units are B, K, m and G, and are not case sensitive"),
},
Validate: func(ans interface{}) error {
str, ok := ans.(string)
if !ok {
return errors.New(LocalSprintf("filesize error one"))
}
match, _ := regexp.MatchString(`^[1-9]+[0-9]*[bBkKmMgG]$`, str)
if !match {
return errors.New(LocalSprintf("filesize error two"))
}
return nil
},
},
{
Name: "fileNumber",
Prompt: &survey.Input{
Message: LocalSprintf("select the number of scan results to display, the default is 3:"),
Default: "3",
Help: LocalSprintf("the default display is the first 3. The maximum page size is 10 rows, so it is best not to exceed 10."),
},
Validate: func(ans interface{}) error {
str, ok := ans.(string)
if !ok {
return errors.New(LocalSprintf("filenumber error one"))
}
match, _ := regexp.MatchString(`^[1-9]+[0-9]*$`, str)
if !match {
return errors.New(LocalSprintf("filenumber error two"))
}
return nil
},
},
}
func (op *Options) SurveyCmd() error {
// the answers will be written to this struct
// you can tag fields to match a specific name
answers := struct {
FileType string `survey:"fileType"`
Threshold string `survey:"fileSize"`
ShowNum uint32 `survey:"fileNumber"`
}{}
// perform the questions
err := survey.Ask(qs, &answers, survey.WithHelpInput('?'))
if err != nil {
return err
}
op.limit = answers.Threshold
op.number = answers.ShowNum
op.types = answers.FileType
return nil
}
func MultiSelectCmd(list BlobList) []string {
selected := []string{}
targets := []string{}
for _, item := range list {
ele := item.oid + ": " + item.objectName + "\n"
targets = append(targets, ele)
}
prompt := &survey.MultiSelect{
Message: LocalSprintf("multi select message") + "\n",
Options: targets,
PageSize: 10,
Help: LocalSprintf("multi select help info"),
}
err := survey.AskOne(prompt, &selected, survey.WithHelpInput('?'))
if err == terminal.InterruptErr {
PrintLocalWithRedln("process interrupted")
os.Exit(1)
}
return selected
}
func Confirm(list []string) (bool, []string) {
ok := false
results := []string{}
prompt := &survey.Confirm{
Message: LocalSprintf("confirm message") + "\n",
}
err := survey.AskOne(prompt, &ok)
if err == terminal.InterruptErr {
PrintLocalWithRedln("process interrupted")
os.Exit(1)
}
// turn back to name oid only
for _, item := range list {
name := strings.Split(item, ":")[0]
results = append(results, name)
}
return ok, results
}
func AskForMigrateToLFS() bool {
ok := false
prompt := &survey.Confirm{
Message: LocalSprintf("ask for migrating big file into LFS") + "\n",
}
err := survey.AskOne(prompt, &ok)
if err == terminal.InterruptErr {
PrintLocalWithRedln("process interrupted")
os.Exit(1)
}
return ok
}
func AskForOverride() bool {
ok := false
prompt := &survey.Confirm{
Message: LocalSprintf("ask for override message") + "\n",
}
err := survey.AskOne(prompt, &ok)
if err == terminal.InterruptErr {
PrintLocalWithRedln("process interrupted")
os.Exit(1)
}
return ok
}
func AskForUpdate() bool {
ok := false
fmt.Println()
prompt := &survey.Confirm{
Message: LocalSprintf("ask for update message") + "\n",
}
err := survey.AskOne(prompt, &ok)
if err == terminal.InterruptErr {
PrintLocalWithRedln("process interrupted")
os.Exit(1)
}
return ok
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。