本文整理汇总了Golang中github.com/knq/xo/internal.ArgType.Filename方法的典型用法代码示例。如果您正苦于以下问题:Golang ArgType.Filename方法的具体用法?Golang ArgType.Filename怎么用?Golang ArgType.Filename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/knq/xo/internal.ArgType
的用法示例。
在下文中一共展示了ArgType.Filename方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: processArgs
// processArgs processs cli args.
func processArgs(args *internal.ArgType) error {
var err error
// get working directory
cwd, err := os.Getwd()
if err != nil {
return err
}
// determine out path
if args.Out == "" {
args.Path = cwd
} else {
// determine what to do with Out
fi, err := os.Stat(args.Out)
if err == nil && fi.IsDir() {
// out is directory
args.Path = args.Out
} else if err == nil && !fi.IsDir() {
// file exists (will truncate later)
args.Path = path.Dir(args.Out)
args.Filename = path.Base(args.Out)
// error if not split was set, but destination is not a directory
if !args.SingleFile {
return errors.New("output path is not directory")
}
} else if _, ok := err.(*os.PathError); ok {
// path error (ie, file doesn't exist yet)
args.Path = path.Dir(args.Out)
args.Filename = path.Base(args.Out)
// error if split was set, but dest doesn't exist
if !args.SingleFile {
return errors.New("output path must be a directory and already exist when not writing to a single file")
}
} else {
return err
}
}
// check user template path
if args.TemplatePath != "" {
fi, err := os.Stat(args.TemplatePath)
if err == nil && !fi.IsDir() {
return errors.New("template path is not directory")
} else if err != nil {
return errors.New("template path must exist")
}
}
// fix path
if args.Path == "." {
args.Path = cwd
}
// determine package name
if args.Package == "" {
args.Package = path.Base(args.Path)
}
// determine filename if not previously set
if args.Filename == "" {
args.Filename = args.Package + args.Suffix
}
// if query mode toggled, but no query, read Stdin.
if args.QueryMode && args.Query == "" {
buf, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return err
}
args.Query = string(buf)
}
// query mode parsing
if args.Query != "" {
args.QueryMode = true
}
// check that query type was specified
if args.QueryMode && args.QueryType == "" {
return errors.New("query type must be supplied for query parsing mode")
}
// query trim
if args.QueryMode && args.QueryTrim {
args.Query = strings.TrimSpace(args.Query)
}
// escape all
if args.EscapeAll {
args.EscapeSchemaName = true
args.EscapeTableNames = true
args.EscapeColumnNames = true
}
// if verbose
if args.Verbose {
//.........这里部分代码省略.........