This repository has been archived by the owner on Dec 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.go
77 lines (66 loc) · 1.8 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"fmt"
"github.com/andiogenes/tinyviz/graphics"
"github.com/andiogenes/tinyviz/input"
"github.com/andiogenes/tinyviz/random"
"os"
"path/filepath"
)
// getDescriptors возвращает срез имен всех файлов-дескрипторов в текущей папке
func getDescriptors() ([]string, error) {
curPath, err := os.Getwd()
if err != nil {
return nil, err
}
var files []string
err = filepath.Walk(curPath, func(path string, f os.FileInfo, errout error) error {
if errout != nil {
return errout
}
if !f.IsDir() {
if filepath.Ext(path) == ".descr" {
files = append(files, f.Name())
}
}
return nil
})
if err != nil {
return nil, err
}
return files, nil
}
// pickFormat ...
func pickFormat(extension string) (graphics.ImageFormat, error) {
switch extension {
case "png":
return graphics.Png, nil
case "jpg", "jpeg":
return graphics.Jpeg, nil
default:
return graphics.Png, fmt.Errorf("Incorrect argument: excepted \"png\", \"jpg\" or \"jpeg\", given \"%s\"", extension)
}
}
// pickArrangementFn ...
func pickArrangementFn(arrangement string) (graphics.ArrangementFn, error) {
switch arrangement {
case "random", "rand", "r":
return graphics.PutVertexInRandomFreeCell, nil
case "coord", "c":
return graphics.PutVertexAtPosition, nil
default:
return nil, fmt.Errorf("Incorrect argument: excepted \"random\", or \"coord\", given \"%s\"", arrangement)
}
}
// initDataLoader ...
func initDataLoader(arrangement string) (input.ArrangementLoader, error) {
switch arrangement {
case "random", "rand", "r":
random.ShuffleSeed()
return nil, nil
case "coord", "c":
return input.CoordinatesLoader, nil
default:
return nil, fmt.Errorf("Incorrect argument: excepted \"random\", or \"coord\", given \"%s\"", arrangement)
}
}