@@ -5,7 +5,10 @@ import (
5
5
"github.com/fatih/color"
6
6
"github.com/urfave/cli/v2"
7
7
"fmt"
8
- "os"
8
+ "os"
9
+ "github.com/chermehdi/egor/config"
10
+ "path"
11
+ "strconv"
9
12
)
10
13
11
14
func readFromStdin () ([]string , error ) {
@@ -22,7 +25,7 @@ func readFromStdin() ([]string, error) {
22
25
lines = append (lines , line )
23
26
}
24
27
25
- // TODO add check for errors
28
+ // TODO(Eroui) add check for errors
26
29
return lines , nil
27
30
}
28
31
@@ -42,19 +45,46 @@ func writeLinesToFile(filename string, lines []string) {
42
45
}
43
46
}
44
47
45
-
46
48
// TODO(Eroui): add checks on errors
47
49
func CustomCaseAction (context * cli.Context ) error {
48
50
color .Green ("Creating Custom Test Case..." )
49
51
52
+ // Load meta data
53
+ cwd , err := os .Getwd ()
54
+ if err != nil {
55
+ return err
56
+ }
57
+
58
+ meta_data , err := config .LoadMetaFromPath (path .Join (cwd , "egor-meta.json" ))
59
+ if err != nil {
60
+ return err
61
+ }
62
+
50
63
color .Green ("Provide your input:" )
51
64
input_lines , _ := readFromStdin ()
52
65
53
66
color .Green ("Provide your output:" )
54
67
output_lines , _ := readFromStdin ()
68
+
69
+ case_name := "test-" + strconv .Itoa (len (meta_data .Inputs ))
55
70
56
- writeLinesToFile ("sample.in" , input_lines )
57
- writeLinesToFile ("sample.out" , output_lines )
71
+ input_file_name := case_name + ".in"
72
+ output_file_name := case_name + ".out"
73
+
74
+ writeLinesToFile ("inputs/" + input_file_name , input_lines )
75
+ writeLinesToFile ("outputs/" + output_file_name , output_lines )
76
+
77
+ input_file := config .NewIoFile (input_file_name , "inputs/" + input_file_name , true )
78
+ output_file := config .NewIoFile (input_file_name , "outputs/" + output_file_name , true )
79
+
80
+ meta_data .Inputs = append (meta_data .Inputs , input_file )
81
+ meta_data .Outputs = append (meta_data .Outputs , output_file )
82
+
83
+ meta_data .SaveToFile (path .Join (cwd , "egor-meta.json" ))
84
+
85
+ if err != nil {
86
+ fmt .Println (err )
87
+ }
58
88
59
89
color .Green ("Created Custom Test Case..." )
60
90
return nil
0 commit comments