2019-11-02 10:54:41 +09:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-12-23 00:07:42 +09:00
|
|
|
"fmt"
|
2020-12-21 19:57:18 +09:00
|
|
|
"os"
|
2020-12-23 00:07:42 +09:00
|
|
|
|
|
|
|
// "runtime/pprof"
|
2021-05-20 17:37:09 +09:00
|
|
|
// "github.com/felixge/fgprof"
|
2020-12-21 19:57:18 +09:00
|
|
|
|
2019-11-02 10:54:41 +09:00
|
|
|
"github.com/akiyosi/goneovim/editor"
|
2020-12-23 00:07:42 +09:00
|
|
|
"github.com/jessevdk/go-flags"
|
2019-11-02 10:54:41 +09:00
|
|
|
)
|
|
|
|
|
2021-08-02 23:08:12 +09:00
|
|
|
|
2019-11-02 10:54:41 +09:00
|
|
|
func main() {
|
2020-12-23 00:07:42 +09:00
|
|
|
// // profile the application
|
|
|
|
// // https://blog.golang.org/pprof
|
|
|
|
// // After running the app, do the following:
|
|
|
|
// // $ go tool pprof -http=localhost:9090 cpuprofile
|
|
|
|
// f, err := os.Create("cpuprofile")
|
|
|
|
// if err != nil {
|
|
|
|
// os.Exit(1)
|
|
|
|
// }
|
|
|
|
// defer f.Close()
|
|
|
|
// pprof.StartCPUProfile(f)
|
|
|
|
// defer pprof.StopCPUProfile()
|
|
|
|
|
2021-05-20 17:37:09 +09:00
|
|
|
// // fgprof
|
|
|
|
// f, err := os.Create("cpuprofile")
|
|
|
|
// if err != nil {
|
|
|
|
// os.Exit(1)
|
|
|
|
// }
|
|
|
|
// fgprofStop := fgprof.Start(f, fgprof.FormatPprof)
|
|
|
|
// defer func() {
|
|
|
|
// err = fgprofStop()
|
|
|
|
// if err != nil {
|
|
|
|
// fmt.Println(err)
|
|
|
|
// }
|
|
|
|
// err = f.Close()
|
|
|
|
// if err != nil {
|
|
|
|
// fmt.Println(err)
|
|
|
|
// }
|
|
|
|
// }()
|
|
|
|
|
2020-12-23 00:07:42 +09:00
|
|
|
// parse args
|
|
|
|
options, args := parseArgs()
|
2021-08-02 23:08:12 +09:00
|
|
|
if options.Version {
|
2021-08-06 23:13:30 +09:00
|
|
|
fmt.Println(editor.Version)
|
2021-08-02 23:08:12 +09:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
2021-01-17 11:24:13 +09:00
|
|
|
|
|
|
|
// start editor
|
2021-08-06 23:13:30 +09:00
|
|
|
editor.InitEditor(options, args)
|
2020-12-23 00:07:42 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// parsArgs parse args
|
|
|
|
func parseArgs() (editor.Options, []string) {
|
|
|
|
var options editor.Options
|
|
|
|
parser := flags.NewParser(&options, flags.HelpFlag|flags.PassDoubleDash)
|
|
|
|
args, err := parser.ParseArgs(os.Args[1:])
|
|
|
|
if flagsErr, ok := err.(*flags.Error); ok {
|
|
|
|
switch flagsErr.Type {
|
|
|
|
case flags.ErrDuplicatedFlag:
|
|
|
|
case flags.ErrHelp:
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2020-12-21 19:57:18 +09:00
|
|
|
}
|
2020-12-17 01:31:07 +09:00
|
|
|
|
2020-12-23 00:07:42 +09:00
|
|
|
return options, args
|
2019-11-02 10:54:41 +09:00
|
|
|
}
|