docs
This commit is contained in:
parent
68e2d0ac1d
commit
bd05d482e2
2 changed files with 10 additions and 3 deletions
|
|
@ -9,12 +9,15 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// NOTE: the -r flag:
|
||||||
LS_CMD = `ls -r [0-9]*.md`
|
LS_CMD = `ls -r [0-9]*.md`
|
||||||
|
// we only care about the number group:
|
||||||
FILE_REGEXP = `(?m)^([0-9]+)\.[[:alpha:]]*\.*md$`
|
FILE_REGEXP = `(?m)^([0-9]+)\.[[:alpha:]]*\.*md$`
|
||||||
)
|
)
|
||||||
|
|
||||||
var fileRegexp *regexp.Regexp = regexp.MustCompile(FILE_REGEXP)
|
var fileRegexp *regexp.Regexp = regexp.MustCompile(FILE_REGEXP)
|
||||||
|
|
||||||
|
// calls ls to get the lexical last file
|
||||||
func last() (string, error) {
|
func last() (string, error) {
|
||||||
// NOTE: globbing requires invoking the shell as cmd:
|
// NOTE: globbing requires invoking the shell as cmd:
|
||||||
cmd := exec.Command("sh", "-c", LS_CMD)
|
cmd := exec.Command("sh", "-c", LS_CMD)
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,9 @@ func parseArgs(args []string) options {
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseFile(last string) (string, error) {
|
// takes the complete last file string
|
||||||
|
// returns the number as string
|
||||||
|
func numFromLast(last string) (string, error) {
|
||||||
res := fileRegexp.FindStringSubmatch(last)
|
res := fileRegexp.FindStringSubmatch(last)
|
||||||
num := ""
|
num := ""
|
||||||
if len(res) < 2 {
|
if len(res) < 2 {
|
||||||
|
|
@ -51,8 +53,10 @@ func parseFile(last string) (string, error) {
|
||||||
return num, nil
|
return num, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// takes the complete last file string and new descriptor
|
||||||
|
// returns the complete next file string
|
||||||
func next(last string, desc string) (string, error) {
|
func next(last string, desc string) (string, error) {
|
||||||
num, err := parseFile(last)
|
num, err := numFromLast(last)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue