You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1005 B
45 lines
1005 B
// go mod init worklog |
|
// go build |
|
// go run . |
|
// go mod tidy |
|
|
|
package main |
|
|
|
import "errors" |
|
import "os" |
|
|
|
import "github.com/alexflint/go-arg" |
|
|
|
import "worklog/src" |
|
|
|
type Args struct { |
|
Decl string `arg:"-d,--decl" help:"Generate travel declaration table" placeholder:"MONTH"` |
|
Process bool `arg:"-p,--process" help:"Process specified file and call Jira API"` |
|
File string `arg:"positional,required" help:"the worklog file to process"` |
|
} |
|
|
|
func (Args) Description() string { |
|
return "\nworklog - process a worklog file\n" |
|
} |
|
|
|
func main() { |
|
var args Args |
|
parser := arg.MustParse(&args) |
|
|
|
_, err := os.Stat(args.File); |
|
if errors.Is(err, os.ErrNotExist) || errors.Is(err, os.ErrPermission) { |
|
parser.Fail("file was not readable: " + args.File) |
|
} |
|
|
|
if args.Process { |
|
var api src.Api = src.MakeApi() |
|
var job = func(line string, line_number int) string { |
|
return api.Process(line, line_number) |
|
} |
|
src.Parse(args.File, job) |
|
} |
|
|
|
if args.Decl != "" { |
|
// TODO: generate declaration table.. |
|
} |
|
}
|
|
|