Skip to content

Commit

Permalink
Quick Save
Browse files Browse the repository at this point in the history
  • Loading branch information
rsdoiel committed Aug 9, 2022
1 parent 322885e commit 26e89b1
Show file tree
Hide file tree
Showing 87 changed files with 2,001 additions and 25,168 deletions.
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ keywords:
- Github
- text markup
- screen play
date-released: 2022-08-08
date-released: 2022-08-09
80 changes: 65 additions & 15 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,39 +85,89 @@ func RunScripttool(in *os.File, out *os.File, eout *os.File, args []string) erro
}

switch verb {
case "fdx2fountain":
return FdxToFountain(in, out)
case "osf2fountain":
return OSFToFountain(in, out)
case "fountain2fdx":
return FountainToFdx(in, out)
case "fountain2osf":
return FountainToOSF(in, out)
case "characters":
return CharacterList(in, out, alphaSort)
// fadein to something
case "fadein2fdx":
if inputFName != "" {
return FadeInToFDX(inputFName, out)
}
return fmt.Errorf("A FadeIn filename required for input")
case "fadein2fountain":
if inputFName != "" {
return FadeInToFountain(inputFName, out)
}
return fmt.Errorf("A FadeIn filename required for input")
case "fadein2json":
if inputFName != "" {
return FadeInToJSON(inputFName, out)

}
return fmt.Errorf("A FadeIn filename required for input")
case "fadein2osf":
if inputFName != "" {
return FadeInToOSF(inputFName, out)

}
return fmt.Errorf("A FadeIn filename must for input")
return fmt.Errorf("A FadeIn filename required for input")

// fdx to something
case "fdx2fadein":
if outputFName != "" {
return FdxToFadeIn(in, outputFName)
}
return fmt.Errorf("A FadeIn filename required for output")
case "fdx2fountain":
return FdxToFountain(in, out)
case "fdx2json":
return FdxToJSON(in, out)
case "fdx2osf":
return FdxToOSF(in, out)

// fountain to something
case "fountain2fadein":
if outputFName != "" {
return FountainToFadeIn(in, outputFName)
}
return fmt.Errorf("A FadeIn filename must for output")
return fmt.Errorf("A FadeIn filename required for output")
case "fountain2fdx":
return FountainToFdx(in, out)
case "fountain2json":
return FountainToJSON(in, out)
case "fountain2osf":
return FountainToOSF(in, out)

// osf to something
case "osf2fadein":
if outputFName != "" {
return OSFToFadeIn(in, outputFName)
}
return fmt.Errorf("A FadeIn filename required for output")
case "osf2fdx":
return OSFToFdx(in, out)
case "osf2fountain":
return OSFToFountain(in, out)
case "osf2json":
return OSFToJSON(in, out)

// Utility fountain functions
case "fountain2fountain":
return FountainToFountain(in, out)
case "fountainfmt":
return FountainFmt(in, out)
case "fountain2html":
return FountainToHTML(in, out)
case "fountain2json":
return FountainToJSON(in, out)
case "characters":
//FIXME: add detection of file type, convert to fountain then
// run report.
return CharacterList(in, out, alphaSort)

// Help system
case "help":
fmt.Fprintln(out, FmtCliText(HelpText, appName, verb, Version))
return nil

// If we got this far we have an unknown verb
default:
return fmt.Errorf("do not understand %q in %q", verb, strings.Join(args, " "))

}
return nil
}
58 changes: 56 additions & 2 deletions cli_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,61 @@
package scripttool

import "testing"
import (
"io/fs"
"os"
"path"
"strings"
"testing"
)

var (
testdataBase = "testdata"
testoutBase = "testout"
)

func TestRunScripttool(t *testing.T) {
t.Fatal("not implemented")
var verb string
appName := os.Args[0]
// Run the JSON command
if _, err := os.Stat(testoutBase); err == nil {
os.RemoveAll(testoutBase)
}
os.MkdirAll(testoutBase, 0775)
fSys := os.DirFS(testdataBase)
fs.WalkDir(fSys, ".", func(p string, info fs.DirEntry, err error) error {
if !info.IsDir() {
inName := info.Name()
inExt := path.Ext(inName)
outName := strings.TrimSuffix(inName, inExt) + ".json"

//fmt.Printf("DEBUG pth: %q fName: %q, ext: %q\n", p, inName, inExt)
switch inExt {
case ".txt":
verb = "fountain2json"
case ".fountain":
verb = "fountain2json"
case ".fdx":
verb = "fdx2json"
case ".fadein":
verb = "fadein2json"
case ".osf":
verb = "osf2json"
default:
// We're only doing
//fmt.Printf("Skipping %q, unsupported to file extension %q\n", inName, inExt)
return nil
}
// We'll just rely on our standard VERB INPUT_NAME OUTPUT_NAME
in := os.Stdin
out := os.Stdout
eout := os.Stderr
inputFName := path.Join(testdataBase, inName)
outputFName := path.Join(testoutBase, outName)
args := []string{appName, verb, inputFName, outputFName}
if err := RunScripttool(in, out, eout, args); err != nil {
t.Errorf("unexpected error RunScripttool(in, out, eout, %+v) -> %s", args, err)
}
}
return nil
})
}
60 changes: 46 additions & 14 deletions docs/scripttool.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,67 @@ Internally _scripttool_ works with Fountain formatter files for reporting purpos
# verbs

Like many recent command line tools running under POSIX _scripttool_ uses
a `CMD VERB MODIFIERS` scheme. The follownig verbs are provided. Each
"verb" may also have related options.
a `CMD VERB [INPUT_FILENAME] [OUTPUT_FILENAME]` scheme. The follownig verbs are provided. Each "verb" may also have related options.

## Convert FadeIn files

fadein2fdx
: Converts a FadeIn file to Final Draft XML

fadein2fountain
: Converts a FadeIn file to fountain screenplay format

fadein2json
: Convert a FadeIn file to JSON format

fadein2osf
: Convert a FadeIn file to Open Screenplay Format 2.0

## Convert Final Draft XML

fdx2fadein
: Convert from Final Draft XML ("*.fdx" files) to FadeIn format

fdx2fountain
: Convert from Final Draft XML ("*.fdx" files) to Fountain screenplay format)

fdx2json
: Convert from Final Draft XML ("*.fdx" files) to JSON

fdx2osf
: Convert from Final Draft XML ("*.fdx" files) to Open Screenplay Format 2.0

## Convert Open Screenplay Format 2.0

osf2fadein
: Convert from Open Screenplay Format 2.0 to FadeIn

osf2fdx
: Convert from Open Screenplay Format 2.0 to Final Draft XML

osf2fountain
: Convert from Open Screenplay Format 2.0 to Fountain screenplay format

osf2json
: Convert from Open Screenplay Format 2.0 to JSON

## Convert Fountain fomat

fountain2fadein
: Converts a fountain screenplay formatted file to FadeIn formatted file.

fountain2fdx
: Convert a Fountain screenplay formatted file to Final Draft XML

fountain2json
: Convert a Fountain screenplay formatted file to JSON

fountain2osf
: Convert a Fountain screenplay formatted file to Open Screenplay Format 2.0

fadein2fountain
: Converts a FadeIn file to fountain screenplay format

fountain2fadein
: Converts a fountain screenplay formatted file to FadeIn formatted file.

fountainfmt
: Pretty print a fountain screenplay format

fountain2json
: Convert a fountain screenplay to JSON for machine or data processing

characters
: Provide a character list from a fountain formatted file. Internally the fountain file is parse and resulting JSON structure is analyzed to produce the count of character references in the elements of the file.

Expand Down Expand Up @@ -119,12 +153,10 @@ Converting *screenplay.fountain* to *screenplay.fdx* (2 examples)
scripttool fountain2fdx -i screenplay.fountain -o screenplay.fdx
~~~

Listing characters in *screenplay.fountain*. First list is order of appearence and the second set is characters sorted alphabetically using the "-alpha" option. (2 examples each)
Listing characters from a *screenplay.fountain*. First list is order of appearence and the second set is characters sorted alphabetically using the "-alpha" option.

~~~shell
scripttool characters screenplay.fountain
scripttool characters -i screenplay.fountain
scripttool characters -alpha screenplay.fountain
scripttool characters -alpha -i screenplay.fountain
~~~

11 changes: 6 additions & 5 deletions fdx/fdx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (

var (
expectedDocs map[string][]byte
testdataBase = path.Join("..", "testdata")
)

func testFdxFile(t *testing.T, fname string) {
Expand All @@ -59,11 +60,11 @@ func testFdxFile(t *testing.T, fname string) {
if err := xml.Unmarshal(src, &fdx); err != nil {
t.Errorf("%s", err)
} else {
os.RemoveAll(path.Join("testout", path.Base(fname)))
os.RemoveAll(path.Join(testdataBase, path.Base(fname)))
if src2, err := xml.MarshalIndent(fdx, " ", " "); err != nil {
t.Errorf("%s", err)
} else {
if err := ioutil.WriteFile(path.Join("testout", path.Base(fname)), src2, 0666); err != nil {
if err := ioutil.WriteFile(path.Join(testdataBase, path.Base(fname)), src2, 0666); err != nil {
t.Errorf("%s", err)
}
}
Expand All @@ -80,7 +81,7 @@ func TestConversion(t *testing.T) {
"sample-03.fdx",
}
for _, fname := range fileList {
testFdxFile(t, path.Join("testdata", fname))
testFdxFile(t, path.Join(testdataBase, fname))
}
}

Expand All @@ -91,7 +92,7 @@ func TestTitlePageToString(t *testing.T) {
"sample-02.fdx",
}
for _, fname := range noTitlePages {
fullName := path.Join("testdata", fname)
fullName := path.Join(testdataBase, fname)
src, err := ioutil.ReadFile(fullName)
if err != nil {
t.Errorf("%s", err)
Expand All @@ -118,7 +119,7 @@ func TestTitlePageToString(t *testing.T) {
"sample-03.fdx": []string{"SAMPLE 03"},
}
for fname, textTerms := range haveTitlePages {
src, err := ioutil.ReadFile(path.Join("testdata", fname))
src, err := ioutil.ReadFile(path.Join(testdataBase, fname))
if err != nil {
if strings.HasPrefix(fname, "sample") == true {
t.Errorf("%s", err)
Expand Down
Binary file removed fdx/testdata/sample-01.fadein
Binary file not shown.
Loading

0 comments on commit 26e89b1

Please sign in to comment.