Skip to content

Commit

Permalink
chore: re-generate the readme docs for timex
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Apr 21, 2022
1 parent 1e8c76f commit a315a14
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 26 deletions.
50 changes: 33 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,38 @@ func TodayEnd() time.Time
func HowLongAgo(sec int64) string
func ToLayout(template string) string
```
#### Usage

- **Convert time to date by template**

```text
Template Vars:
Y,y - year
Y - year 2006
y - year 06
M,m - month 01
D,d - day 02
H,h - hour 15
I,i - minute 04
S,s - second 05
```

Examples, use timex:

```go
now := timex.Now()
date := now.DateFormat("Y-M-D H:i:s") // Output: 2022-04-20 19:40:34
date = now.DateFormat("y-M-D H:i:s") // Output: 22-04-20 19:40:34
```

Format time.Time:

```go
now := time.Now()
date := timex.DateFormat(now, "Y-M-D H:i:s") // Output: 2022-04-20 19:40:34
```



## Code Check & Testing

Expand Down Expand Up @@ -842,23 +874,7 @@ go test ./...
## License

[MIT](LICENSE)
l
func StdIsTerminal() bool
func CurrentShell(onlyName bool) (path string)
func HasShellEnv(shell string) bool
func IsShellSpecialVar(c uint8) bool
// source at sysutil/sysutil.go
func Workdir() string
func BinDir() string
func BinFile() string
// source at sysutil/sysutil_nonwin.go
func Kill(pid int, signal syscall.Signal) error
func ProcessExists(pid int) bool
// source at sysutil/user.go
func MustFindUser(uname string) *user.User
func LoginUser() *user.User
func CurrentUser() *user.User
func UserHomeDir() string
string
func UHomeDir() string
func HomeDir() string
func UserDir(subPath string) string
Expand Down
32 changes: 32 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,38 @@ func TodayEnd() time.Time
func HowLongAgo(sec int64) string
func ToLayout(template string) string
```
#### Usage

- **Convert time to date by template**

```text
Template Vars:
Y,y - year
Y - year 2006
y - year 06
M,m - month 01
D,d - day 02
H,h - hour 15
I,i - minute 04
S,s - second 05
```

Examples, use timex:

```go
now := timex.Now()
date := now.DateFormat("Y-M-D H:i:s") // Output: 2022-04-20 19:40:34
date = now.DateFormat("y-M-D H:i:s") // Output: 22-04-20 19:40:34
```

Format time.Time:

```go
now := time.Now()
date := timex.DateFormat(now, "Y-M-D H:i:s") // Output: 2022-04-20 19:40:34
```



## Code Check & Testing

Expand Down
20 changes: 11 additions & 9 deletions internal/gendoc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ var (
// short name => full name.
pkgNames = make(map[string]string, 16)

partDocTplS = "/part-%s-s%s.md"
partDocTplE = "/part-%s%s.md"
partDocTplS = "part-%s-s%s.md"
partDocTplE = "part-%s%s.md"
)

func bindingFlags() {
Expand Down Expand Up @@ -244,6 +244,8 @@ func collectPgkFunc(ms []string, basePkg string) *bytes.Buffer {

if len(pkgFuncs) > 0 {
bufWriteln(buf, "```")
// load last sub-pkg doc file.
bufWriteDoc(buf, partDocTplE, dirname)
}

return buf
Expand All @@ -263,22 +265,22 @@ func bufWriteDoc(buf *bytes.Buffer, partNameTpl, pkgName string) {
lang = "." + genOpts.lang
}

partName := fmt.Sprintf(partNameTpl, pkgName, lang)
filename := fmt.Sprintf(partNameTpl, pkgName, lang)

if !doWriteDoc2buf(buf, partName) {
if !doWriteDoc2buf(buf, filename) {
// fallback use en docs
partName = fmt.Sprintf(partNameTpl, pkgName, "")
doWriteDoc2buf(buf, partName)
filename = fmt.Sprintf(partNameTpl, pkgName, "")
doWriteDoc2buf(buf, filename)
}
}

func doWriteDoc2buf(buf *bytes.Buffer, partName string) bool {
partFile := genOpts.tplDir + partName
func doWriteDoc2buf(buf *bytes.Buffer, filename string) bool {
partFile := genOpts.tplDir + "/" + filename
// color.Infoln("- try read part readme from", partFile)
partBody := fsutil.ReadExistFile(partFile)

if len(partBody) > 0 {
color.Infoln("- find and inject sub-package doc:", partName)
color.Infoln("- find and inject sub-package doc:", filename)
_, _ = fmt.Fprintln(buf, string(partBody))
return true
}
Expand Down

0 comments on commit a315a14

Please sign in to comment.