mirror of
https://github.com/felixangell/phi.git
synced 2024-08-16 11:10:37 +03:00
Merge pull request #24 from clee/create-nonexistent-file-args
Create nonexistent file arguments on launch
This commit is contained in:
commit
5dc4710546
@ -3,6 +3,7 @@ package gui
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"runtime"
|
||||
@ -79,6 +80,15 @@ func (b *Buffer) OpenFile(filePath string) {
|
||||
b.languageInfo = lang
|
||||
}
|
||||
|
||||
// if the file doesn't exist, try to create it before reading it
|
||||
if _, err := os.Stat(filePath); os.IsNotExist(err) {
|
||||
if f, err = os.Create(filePath); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
f.Close()
|
||||
}
|
||||
}
|
||||
|
||||
contents, err := ioutil.ReadFile(filePath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
Loading…
Reference in New Issue
Block a user