cleanup
This commit is contained in:
1 parent
1a39b00a8f
commit
9b7bf63096
16 files changed
+566
-684
No files matched your search
@@ -26,12 +26,11 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
|
||||
gHostname, err = os.Hostname()
|
||||
h, err := os.Hostname()
|
||||
if err != nil {
|
||||
log.Printf("hostname: %s", err)
|
||||
}
|
||||
gHostname = h
|
||||
}
|
||||
|
||||
func startServer() {
|
||||
@@ -42,18 +41,52 @@ func startServer() {
|
||||
}
|
||||
|
||||
func main() {
|
||||
showDoc := flag.Bool("doc", false, "show documentation")
|
||||
remoteCmd := flag.String("remote", "", "send remote command to server")
|
||||
serverMode := flag.Bool("server", false, "start server (automatic)")
|
||||
cpuprofile := flag.String("cpuprofile", "", "path to the file to write the cpu profile")
|
||||
flag.StringVar(&gLastDirPath, "last-dir-path", "", "path to the file to write the last dir on exit (to use for cd)")
|
||||
flag.StringVar(&gSelectionPath, "selection-path", "", "path to the file to write selected files on open (to use as open file dialog)")
|
||||
showDoc := flag.Bool(
|
||||
"doc",
|
||||
false,
|
||||
"show documentation")
|
||||
|
||||
remoteCmd := flag.String(
|
||||
"remote",
|
||||
"",
|
||||
"send remote command to server")
|
||||
|
||||
serverMode := flag.Bool(
|
||||
"server",
|
||||
false,
|
||||
"start server (automatic)")
|
||||
|
||||
cpuprofile := flag.String(
|
||||
"cpuprofile",
|
||||
"",
|
||||
"path to the file to write the cpu profile")
|
||||
|
||||
flag.StringVar(&gLastDirPath,
|
||||
"last-dir-path",
|
||||
"",
|
||||
"path to the file to write the last dir on exit (to use for cd)")
|
||||
|
||||
flag.StringVar(&gSelectionPath,
|
||||
"selection-path",
|
||||
"",
|
||||
"path to the file to write selected files on open (to use as open file dialog)")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
gSocketProt = gDefaultSocketProt
|
||||
gSocketPath = gDefaultSocketPath
|
||||
|
||||
if *cpuprofile != "" {
|
||||
f, err := os.Create(*cpuprofile)
|
||||
if err != nil {
|
||||
log.Fatalf("could not create CPU profile: %s", err)
|
||||
}
|
||||
if err := pprof.StartCPUProfile(f); err != nil {
|
||||
log.Fatalf("could not start CPU profile: %s", err)
|
||||
}
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
|
||||
switch flag.NArg() {
|
||||
case 0:
|
||||
case 1:
|
||||
@@ -67,33 +100,17 @@ func main() {
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
if *showDoc {
|
||||
switch {
|
||||
case *showDoc:
|
||||
fmt.Print(genDocString)
|
||||
return
|
||||
}
|
||||
|
||||
if *remoteCmd != "" {
|
||||
case *remoteCmd != "":
|
||||
if err := sendRemote(*remoteCmd); err != nil {
|
||||
log.Fatalf("remote command: %s", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if *cpuprofile != "" {
|
||||
f, err := os.Create(*cpuprofile)
|
||||
if err != nil {
|
||||
log.Fatalf("could not create CPU profile: %s", err)
|
||||
}
|
||||
if err := pprof.StartCPUProfile(f); err != nil {
|
||||
log.Fatalf("could not start CPU profile: %s", err)
|
||||
}
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
|
||||
if *serverMode {
|
||||
case *serverMode:
|
||||
gServerLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.server.log", gUser.Username))
|
||||
serve()
|
||||
} else {
|
||||
default:
|
||||
// TODO: check if the socket is working
|
||||
if _, err := os.Stat(gSocketPath); os.IsNotExist(err) {
|
||||
startServer()
|
||||
@@ -101,11 +118,11 @@ func main() {
|
||||
|
||||
gClientID = 1000
|
||||
gLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.%d.log", gUser.Username, gClientID))
|
||||
for _, err := os.Stat(gLogPath); err == nil; _, err = os.Stat(gLogPath) {
|
||||
for _, err := os.Stat(gLogPath); !os.IsNotExist(err); _, err = os.Stat(gLogPath) {
|
||||
gClientID++
|
||||
gLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.%d.log", gUser.Username, gClientID))
|
||||
}
|
||||
|
||||
client()
|
||||
run()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user