Compare commits

..

1 commit

Author SHA1 Message Date
f1a13c9cfa chore(deps): update dependency bootstrap to v5.3.6
All checks were successful
continuous-integration/drone/push Build is passing
2025-05-07 11:43:41 +00:00
3 changed files with 13 additions and 37 deletions

View file

@ -4,46 +4,30 @@ import (
"archive/zip" "archive/zip"
"errors" "errors"
"io" "io"
"log"
"os" "os"
"path" "path"
) )
type archiveFileCreator interface { type archiveFileCreator interface {
Create(name string) (io.Writer, error) Create(name string) (io.Writer, error)
Close() error
}
type filesCloser []io.Closer
func (fds filesCloser) Close() error {
log.Println("Closing fd..")
for _, fd := range fds {
err := fd.Close()
if err != nil {
return err
}
}
return nil
} }
func init() { func init() {
OutputFormats["archive"] = func(args ...string) (func(string) (io.WriteCloser, error), io.Closer, error) { OutputFormats["archive"] = func(args ...string) (func(string) (io.WriteCloser, error), error) {
if len(args) != 1 { if len(args) != 1 {
return nil, nil, errors.New("archive has 1 required argument: [destination-file]") return nil, errors.New("archive has 1 required argument: [destination-file]")
} }
fd, err := os.Create(args[0]) fd, err := os.Create(args[0])
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
var w archiveFileCreator var w archiveFileCreator
if path.Ext(args[0]) == ".zip" { if path.Ext(args[0]) == ".zip" {
w = zip.NewWriter(fd) w = zip.NewWriter(fd)
} else { } else {
return nil, nil, errors.New("destination file has to have .zip extension") return nil, errors.New("destination file has to have .zip extension")
} }
return func(dest string) (io.WriteCloser, error) { return func(dest string) (io.WriteCloser, error) {
@ -53,6 +37,6 @@ func init() {
} }
return NopCloser(fw), nil return NopCloser(fw), nil
}, filesCloser{w, fd}, nil }, nil
} }
} }

View file

@ -8,15 +8,15 @@ import (
) )
func init() { func init() {
OutputFormats["copy"] = func(args ...string) (func(string) (io.WriteCloser, error), io.Closer, error) { OutputFormats["copy"] = func(args ...string) (func(string) (io.WriteCloser, error), error) {
if len(args) > 1 { if len(args) > 1 {
return nil, nil, errors.New("copy can only take 1 argument: [destination-folder]") return nil, errors.New("copy can only take 1 argument: [destination-folder]")
} }
if len(args) == 1 { if len(args) == 1 {
fic.FilesDir = args[0] fic.FilesDir = args[0]
} }
return nil, nil, nil return nil, nil
} }
} }

View file

@ -14,7 +14,7 @@ import (
"srs.epita.fr/fic-server/libfic" "srs.epita.fr/fic-server/libfic"
) )
var OutputFormats = map[string]func(...string) (func(string) (io.WriteCloser, error), io.Closer, error){} var OutputFormats = map[string]func(...string) (func(string) (io.WriteCloser, error), error){}
func exportThemeFiles(tdir string) (errs error) { func exportThemeFiles(tdir string) (errs error) {
theme, exceptions, err := sync.BuildTheme(sync.GlobalImporter, tdir) theme, exceptions, err := sync.BuildTheme(sync.GlobalImporter, tdir)
@ -129,13 +129,6 @@ func main() {
log.Println("Using", sync.GlobalImporter.Kind()) log.Println("Using", sync.GlobalImporter.Kind())
hasError := doExport()
if hasError {
os.Exit(1)
}
}
func doExport() bool {
// Configure destination // Configure destination
if flag.NArg() < 1 { if flag.NArg() < 1 {
var formats []string var formats []string
@ -154,10 +147,7 @@ func doExport() bool {
log.Fatal("Please define wanted output format between [" + strings.Join(formats, " ") + "]") log.Fatal("Please define wanted output format between [" + strings.Join(formats, " ") + "]")
} else { } else {
fw, closer, err := outputFormat(flag.Args()[1:]...) fw, err := outputFormat(flag.Args()[1:]...)
if closer != nil {
defer closer.Close()
}
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} else if fw != nil { } else if fw != nil {
@ -180,5 +170,7 @@ func doExport() bool {
} }
} }
return hasError if hasError {
os.Exit(1)
}
} }