fix: create the file passed on the command line when it is missing
A path that did not exist was silently ignored: plotzilla new-script.fountain opened an untitled document instead of a new script saved to that file on the first save.
This commit is contained in:
1 parent
b0bcb812b1
commit
6622203506
3 files changed
+9
-4
No files matched your search
@@ -15,6 +15,8 @@ version is in the `VERSION` file.
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- `plotzilla new-script.fountain` opens a new script that will be saved to that file,
|
||||||
|
instead of an untitled document that forgot the name it was given.
|
||||||
- The unsaved-changes marker is now updated atomically: an edit landing while a save
|
- The unsaved-changes marker is now updated atomically: an edit landing while a save
|
||||||
finished could make the close confirmation unreliable.
|
finished could make the close confirmation unreliable.
|
||||||
- Saving is now durable: the file is synced to disk before it replaces the old one (a
|
- Saving is now durable: the file is synced to disk before it replaces the old one (a
|
||||||
|
|||||||
@@ -89,13 +89,18 @@ func (a *App) beforeClose(ctx context.Context) bool {
|
|||||||
|
|
||||||
func (a *App) NewDocument() *screenplay.Document { return screenplay.New() }
|
func (a *App) NewDocument() *screenplay.Document { return screenplay.New() }
|
||||||
|
|
||||||
// InitialFile returns the script passed on the command line, if any.
|
// InitialFile returns the script passed on the command line, if any. A
|
||||||
|
// path that does not exist yet opens a new script, written there on the
|
||||||
|
// first save: `plotzilla new-script.fountain` creates the file.
|
||||||
func (a *App) InitialFile() (*OpenResult, error) {
|
func (a *App) InitialFile() (*OpenResult, error) {
|
||||||
if a.initialPath == "" {
|
if a.initialPath == "" {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
path := a.initialPath
|
path := a.initialPath
|
||||||
a.initialPath = ""
|
a.initialPath = ""
|
||||||
|
if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
|
||||||
|
return &OpenResult{Path: path, Document: screenplay.New()}, nil
|
||||||
|
}
|
||||||
return a.load(path)
|
return a.load(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,9 +29,7 @@ func main() {
|
|||||||
app := NewApp()
|
app := NewApp()
|
||||||
for _, arg := range os.Args[1:] {
|
for _, arg := range os.Args[1:] {
|
||||||
if !strings.HasPrefix(arg, "-") {
|
if !strings.HasPrefix(arg, "-") {
|
||||||
if _, err := os.Stat(arg); err == nil {
|
app.initialPath = arg // may not exist yet: then it is a new script
|
||||||
app.initialPath = arg
|
|
||||||
}
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user