@@ -16,7 +16,8 @@ use std::{env, panic, process, thread, time::Duration};
1616
1717use ABCoder :: {
1818 compress:: compress:: compress_all,
19- repo:: { self , CompressOptions } ,
19+ export:: { self , ExportOptions } ,
20+ parse:: { self , CompressOptions } ,
2021} ;
2122
2223#[ derive( Clone , Debug ) ]
@@ -27,25 +28,8 @@ struct Options {
2728
2829#[ derive( Clone , Debug ) ]
2930enum 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 ) ,
4933}
5034
5135fn main ( ) {
@@ -56,23 +40,28 @@ fn main() {
5640 match options. action {
5741 Action :: Compress ( cmp) => {
5842 if cmp. force_update_ast {
59- merge_compress ( & options. repo_path , & cmp) ;
43+ merge_repo ( & options. repo_path , & cmp) ;
6044 }
6145 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 ) ;
6549 }
6650 }
6751}
6852
6953const 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
7665" ;
7766
7867fn parse_options ( ) -> Options {
@@ -84,13 +73,10 @@ fn parse_options() -> Options {
8473
8574 let action = match args[ 1 ] . as_str ( ) {
8675 "compress" => {
87- let mut compress_action = CompressAction :: default ( ) ;
76+ let mut compress_action = CompressOptions :: default ( ) ;
8877 if args. len ( ) > 3 {
8978 for i in 3 ..args. len ( ) {
9079 match args[ i] . as_str ( ) {
91- "--export-compress" => {
92- compress_action. export_compress = true ;
93- }
9480 "--force-update-ast" => {
9581 compress_action. force_update_ast = true ;
9682 }
@@ -104,10 +90,34 @@ fn parse_options() -> Options {
10490 }
10591 }
10692 }
107-
10893 Action :: Compress ( compress_action)
10994 }
11095
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+
111121 _ => {
112122 println ! ( "{}" , USAGE ) ;
113123 process:: exit ( 1 ) ;
@@ -120,17 +130,22 @@ fn parse_options() -> Options {
120130 }
121131}
122132
123- fn compress ( repo_path : & String , cmp : & CompressAction ) {
133+ fn compress ( repo_path : & String , cmp : & CompressOptions ) {
124134 // recoverable logic
125135 let run = || {
126136 // get the repo
127- let repo = repo :: get_repo ( repo_path, & cmp. to_compress_options ( ) ) ;
137+ let repo = parse :: get_repo ( repo_path, & cmp) ;
128138 if let Err ( err) = repo {
129139 println ! ( "get repo error: {:?}" , err) ;
130140 process:: exit ( 1 ) ;
131141 }
132142
133143 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+ }
134149
135150 // compress the repo
136151 println ! ( "compressing repo: {}" , repo. id) ;
@@ -157,9 +172,9 @@ fn compress(repo_path: &String, cmp: &CompressAction) {
157172 }
158173}
159174
160- fn export_compress ( repo_path : & String , cmp : & CompressAction ) {
175+ fn export ( repo_path : & String , cmp : & ExportOptions ) {
161176 // 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 ( ) ) ;
163178 if let Err ( err) = repo {
164179 println ! ( "get repo error: {:?}" , err) ;
165180
@@ -170,24 +185,22 @@ fn export_compress(repo_path: &String, cmp: &CompressAction) {
170185
171186 // export the compress
172187 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) ;
176189
177- println ! ( "successfully compressed repo: {}" , repo. id) ;
190+ println ! ( "successfully exported repo: {}" , repo. id) ;
178191}
179192
180- fn merge_compress ( repo_path : & String , cmp : & CompressAction ) {
193+ fn merge_repo ( repo_path : & String , cmp : & CompressOptions ) {
181194 // get old repo
182- let repo = repo :: get_repo ( repo_path, & cmp. to_compress_options ( ) ) ;
195+ let repo = parse :: get_repo ( repo_path, & cmp) ;
183196 if let Err ( err) = repo {
184197 println ! ( "get repo error: {:?}" , err) ;
185198 process:: exit ( 1 ) ;
186199 }
187200 let mut repo = repo. unwrap ( ) ;
188201
189202 // 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) ;
191204 if let Err ( err) = nrepo {
192205 println ! ( "parse repo error: {:?}" , err) ;
193206 process:: exit ( 1 ) ;
0 commit comments