-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.go
94 lines (80 loc) · 1.95 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// Copyright (c) 2018 Dean Jackson <[email protected]>
//
// MIT Licence. See http://opensource.org/licenses/MIT
//
// Created on 2018-01-26
//
package main
import (
"flag"
"log"
"path/filepath"
"github.com/davecgh/go-spew/spew"
aw "github.com/deanishe/awgo"
"github.com/deanishe/awgo/update"
)
const (
issueTrackerURL = "https://github.com/deanishe/alfred-sublime-text/issues"
forumThreadURL = "https://www.alfredforum.com/topic/4510-find-and-open-sublime-text-projects/"
repo = "deanishe/alfred-sublime-text"
)
var (
cacheKey = "sublime-projects.json"
fileExtension = ".sublime-project"
configFile string
wf *aw.Workflow
)
func init() {
wf = aw.New(update.GitHub(repo), aw.HelpURL(issueTrackerURL))
configFile = filepath.Join(wf.DataDir(), "sublime.toml")
}
// workflow entry point
func run() {
var err error
if err = cli.Parse(wf.Args()); err != nil {
if err == flag.ErrHelp {
return
}
wf.FatalError(err)
}
opts.Query = cli.Arg(0)
// Load configuration file
if err = initConfig(); err != nil {
log.Printf("couldn't create config (%s): %v", configFile, err)
wf.Fatal("Couldn't create config. Check log file.")
}
if conf, err = loadConfig(configFile); err != nil {
log.Printf("couldn't read config (%s): %v", configFile, err)
wf.Fatal("Couldn't read config. Check log file.")
}
log.Printf("%#v", opts)
if wf.Debug() {
log.Printf("args=%#v => %#v", wf.Args(), cli.Args())
log.Print(spew.Sdump(conf))
}
// Naughtily switch globals to propagate VSCode mode
if conf.VSCode {
cacheKey = "vscode-projects.json"
fileExtension = ".code-workspace"
}
if opts.SetConfig != "" {
runSetConfig()
} else if opts.Config {
runConfig()
} else if opts.Rescan {
runScan()
} else if opts.Open {
runOpen()
} else if opts.OpenFolders {
runOpenFolders()
} else if opts.Search {
runSearch()
} else {
runOpenPaths()
}
}
// wrap run() in AwGo to catch and display panics
func main() {
wf.Run(run)
}