mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
add Scan/Scanf functions for gcmd; improve gfile.IsEmpty
This commit is contained in:
@ -10,6 +10,4 @@ func main() {
|
||||
user, err := test.ModelUser().One()
|
||||
g.Dump(err)
|
||||
g.Dump(user)
|
||||
user.Password = "1"
|
||||
g.Dump(user.Update())
|
||||
}
|
||||
|
||||
@ -1,23 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"fmt"
|
||||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
"github.com/gogf/gf/os/gcmd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
data := [][]string{
|
||||
[]string{"1/1/2014", "Domain name", "2233", "$10.98"},
|
||||
[]string{"1/1/2014", "January Hosting", "2233", "$54.95"},
|
||||
[]string{"1/4/2014", "February Hosting", "2233", "$51.00"},
|
||||
[]string{"1/4/2014", "February Extra Bandwidth", "2233", "$30.00"},
|
||||
}
|
||||
|
||||
table := tablewriter.NewWriter(os.Stdout)
|
||||
table.SetBorder(false)
|
||||
table.SetRowLine(false)
|
||||
table.SetColumnSeparator("")
|
||||
table.AppendBulk(data)
|
||||
table.Render()
|
||||
fmt.Println(gcmd.Scan("input:"))
|
||||
}
|
||||
|
||||
26
os/gcmd/gcmd_scan.go
Normal file
26
os/gcmd/gcmd_scan.go
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
//
|
||||
|
||||
package gcmd
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Scan prints <info> to stdout, reads and returns user input, which stops by '\n'.
|
||||
func Scan(info ...interface{}) string {
|
||||
var s string
|
||||
fmt.Print(info...)
|
||||
fmt.Scan(&s)
|
||||
return s
|
||||
}
|
||||
|
||||
// Scanf prints <info> to stdout with <format>, reads and returns user input, which stops by '\n'.
|
||||
func Scanf(format string, info ...interface{}) string {
|
||||
var s string
|
||||
fmt.Printf(format, info...)
|
||||
fmt.Scan(&s)
|
||||
return s
|
||||
}
|
||||
@ -407,20 +407,22 @@ func Dir(path string) string {
|
||||
// IsEmpty checks whether the given <path> is empty.
|
||||
// If <path> is a folder, it checks if there's any file under it.
|
||||
// If <path> is a file, it checks if the file size is zero.
|
||||
//
|
||||
// Note that it returns true if <path> does not exist.
|
||||
func IsEmpty(path string) bool {
|
||||
stat, err := Stat(path)
|
||||
if err != nil {
|
||||
return false
|
||||
return true
|
||||
}
|
||||
if stat.IsDir() {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return false
|
||||
return true
|
||||
}
|
||||
defer file.Close()
|
||||
names, err := file.Readdirnames(-1)
|
||||
if err != nil {
|
||||
return false
|
||||
return true
|
||||
}
|
||||
return len(names) == 0
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user