@@ -16,7 +16,8 @@ use std::{env, panic, process, thread, time::Duration};
16
16
17
17
use ABCoder :: {
18
18
compress:: compress:: compress_all,
19
- repo:: { self , CompressOptions } ,
19
+ export:: { self , ExportOptions } ,
20
+ parse:: { self , CompressOptions } ,
20
21
} ;
21
22
22
23
#[ derive( Clone , Debug ) ]
@@ -27,25 +28,8 @@ struct Options {
27
28
28
29
#[ derive( Clone , Debug ) ]
29
30
enum Action {
30
- Compress ( CompressAction ) ,
31
- }
32
-
33
- #[ derive( Clone , Debug , Default ) ]
34
- struct CompressAction {
35
- export_compress : bool ,
36
- force_update_ast : bool ,
37
- not_load_external_symbol : bool ,
38
- no_need_comment : bool ,
39
- }
40
-
41
- impl CompressAction {
42
- fn to_compress_options ( & self ) -> CompressOptions {
43
- CompressOptions {
44
- export_compress : self . export_compress ,
45
- not_load_external_symbol : self . not_load_external_symbol ,
46
- no_need_comment : self . no_need_comment ,
47
- }
48
- }
31
+ Compress ( CompressOptions ) ,
32
+ Export ( ExportOptions ) ,
49
33
}
50
34
51
35
fn main ( ) {
@@ -56,23 +40,28 @@ fn main() {
56
40
match options. action {
57
41
Action :: Compress ( cmp) => {
58
42
if cmp. force_update_ast {
59
- merge_compress ( & options. repo_path , & cmp) ;
43
+ merge_repo ( & options. repo_path , & cmp) ;
60
44
}
61
45
compress ( & options. repo_path , & cmp) ;
62
- if cmp . export_compress {
63
- export_compress ( & options . repo_path , & cmp ) ;
64
- }
46
+ }
47
+ Action :: Export ( exp ) => {
48
+ export ( & options . repo_path , & exp ) ;
65
49
}
66
50
}
67
51
}
68
52
69
53
const USAGE : & str = "Usage: ABCoder <Action> <RepoPath> [Flags]
70
- Action: compress
71
- compress: compress the repo. Including flags:
72
- --export-compress: export the compress result
73
- --force-update-ast: force parsing repo and merge the previous result
74
- --not-load-external-symbol: not load external external symbols to speed up parsing
75
- --no-need-comment: not need comment in symbol content (only works for Go now)
54
+ Actions:
55
+ compress: compress the repo. Including flags:
56
+ --parse-only: only parse the repo, not compress it
57
+ --export-compress: export the compress result
58
+ --force-update-ast: force parsing repo and merge the previous result
59
+ --not-load-external-symbol: not load external external symbols to speed up parsing
60
+ --no-need-comment: not need comment in symbol content (only works for Go now)
61
+ export: export the compress result to csv or markdown (default). Including flags:
62
+ --csv: export the compress result to csv
63
+ --out-dir <path>: output directory path, default is current directory
64
+ --public-only: only export the public symbols
76
65
" ;
77
66
78
67
fn parse_options ( ) -> Options {
@@ -84,13 +73,10 @@ fn parse_options() -> Options {
84
73
85
74
let action = match args[ 1 ] . as_str ( ) {
86
75
"compress" => {
87
- let mut compress_action = CompressAction :: default ( ) ;
76
+ let mut compress_action = CompressOptions :: default ( ) ;
88
77
if args. len ( ) > 3 {
89
78
for i in 3 ..args. len ( ) {
90
79
match args[ i] . as_str ( ) {
91
- "--export-compress" => {
92
- compress_action. export_compress = true ;
93
- }
94
80
"--force-update-ast" => {
95
81
compress_action. force_update_ast = true ;
96
82
}
@@ -104,10 +90,34 @@ fn parse_options() -> Options {
104
90
}
105
91
}
106
92
}
107
-
108
93
Action :: Compress ( compress_action)
109
94
}
110
95
96
+ "export" => {
97
+ let mut opts = ExportOptions :: default ( ) ;
98
+ if args. len ( ) > 3 {
99
+ for i in 3 ..args. len ( ) {
100
+ match args[ i] . as_str ( ) {
101
+ "--out-dir" => {
102
+ if args. len ( ) <= i + 1 {
103
+ println ! ( "--out-dir must specify a value" ) ;
104
+ process:: exit ( 1 ) ;
105
+ }
106
+ opts. output = Some ( args[ i + 1 ] . clone ( ) ) ;
107
+ }
108
+ "--csv" => {
109
+ opts. csv = true ;
110
+ }
111
+ "--public-only" => {
112
+ opts. public_only = true ;
113
+ }
114
+ _ => { }
115
+ }
116
+ }
117
+ }
118
+ Action :: Export ( opts)
119
+ }
120
+
111
121
_ => {
112
122
println ! ( "{}" , USAGE ) ;
113
123
process:: exit ( 1 ) ;
@@ -120,17 +130,22 @@ fn parse_options() -> Options {
120
130
}
121
131
}
122
132
123
- fn compress ( repo_path : & String , cmp : & CompressAction ) {
133
+ fn compress ( repo_path : & String , cmp : & CompressOptions ) {
124
134
// recoverable logic
125
135
let run = || {
126
136
// get the repo
127
- let repo = repo :: get_repo ( repo_path, & cmp. to_compress_options ( ) ) ;
137
+ let repo = parse :: get_repo ( repo_path, & cmp) ;
128
138
if let Err ( err) = repo {
129
139
println ! ( "get repo error: {:?}" , err) ;
130
140
process:: exit ( 1 ) ;
131
141
}
132
142
133
143
let mut repo = repo. unwrap ( ) ;
144
+ repo. save_to_cache ( ) ;
145
+ println ! ( "successfully parsed repo: {}" , repo. id) ;
146
+ if cmp. parse_only {
147
+ return ;
148
+ }
134
149
135
150
// compress the repo
136
151
println ! ( "compressing repo: {}" , repo. id) ;
@@ -157,9 +172,9 @@ fn compress(repo_path: &String, cmp: &CompressAction) {
157
172
}
158
173
}
159
174
160
- fn export_compress ( repo_path : & String , cmp : & CompressAction ) {
175
+ fn export ( repo_path : & String , cmp : & ExportOptions ) {
161
176
// get the repo
162
- let repo = repo :: get_repo ( repo_path, & cmp . to_compress_options ( ) ) ;
177
+ let repo = parse :: get_repo ( repo_path, & CompressOptions :: default ( ) ) ;
163
178
if let Err ( err) = repo {
164
179
println ! ( "get repo error: {:?}" , err) ;
165
180
@@ -170,24 +185,22 @@ fn export_compress(repo_path: &String, cmp: &CompressAction) {
170
185
171
186
// export the compress
172
187
println ! ( "export repo: {}" , repo. id) ;
173
- repo:: export_repo ( & mut repo) ;
174
- // save the compressed repo
175
- repo. save_to_cache ( ) ;
188
+ export:: export_repo ( & mut repo, cmp) ;
176
189
177
- println ! ( "successfully compressed repo: {}" , repo. id) ;
190
+ println ! ( "successfully exported repo: {}" , repo. id) ;
178
191
}
179
192
180
- fn merge_compress ( repo_path : & String , cmp : & CompressAction ) {
193
+ fn merge_repo ( repo_path : & String , cmp : & CompressOptions ) {
181
194
// get old repo
182
- let repo = repo :: get_repo ( repo_path, & cmp. to_compress_options ( ) ) ;
195
+ let repo = parse :: get_repo ( repo_path, & cmp) ;
183
196
if let Err ( err) = repo {
184
197
println ! ( "get repo error: {:?}" , err) ;
185
198
process:: exit ( 1 ) ;
186
199
}
187
200
let mut repo = repo. unwrap ( ) ;
188
201
189
202
// parse new repo
190
- let nrepo = repo :: force_parse_repo ( repo_path, & cmp. to_compress_options ( ) ) ;
203
+ let nrepo = parse :: force_parse_repo ( repo_path, & cmp) ;
191
204
if let Err ( err) = nrepo {
192
205
println ! ( "parse repo error: {:?}" , err) ;
193
206
process:: exit ( 1 ) ;
0 commit comments