Allow non-existant files in command-line args
This commit is contained in:
parent
6e97e8345a
commit
ca4a847547
27
main.go
27
main.go
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
@ -47,22 +48,32 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Load files from command-line arguments
|
||||
// Open files from command-line arguments
|
||||
if len(os.Args) > 1 {
|
||||
for _, path := range os.Args[1:] {
|
||||
file, err := os.Open(path)
|
||||
for i := 1; i < len(os.Args); i++ {
|
||||
_, err := os.Stat(os.Args[i])
|
||||
|
||||
var dirty bool
|
||||
var bytes []byte
|
||||
|
||||
if errors.Is(err, os.ErrNotExist) { // If the file does not exist...
|
||||
dirty = true
|
||||
} else { // If the file exists...
|
||||
file, err := os.Open(os.Args[i])
|
||||
if err != nil {
|
||||
panic("File could not be opened at path " + path)
|
||||
panic("File could not be opened at path " + os.Args[i])
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
bytes, err := ioutil.ReadAll(file)
|
||||
bytes, err = ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
panic("Could not read all of " + path)
|
||||
panic("Could not read all of " + os.Args[i])
|
||||
}
|
||||
}
|
||||
|
||||
textEdit := ui.NewTextEdit(&s, path, string(bytes), &theme)
|
||||
tabContainer.AddTab(path, textEdit)
|
||||
textEdit := ui.NewTextEdit(&s, os.Args[i], string(bytes), &theme)
|
||||
textEdit.Dirty = dirty
|
||||
tabContainer.AddTab(os.Args[i], textEdit)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user