@@ -155,7 +155,72 @@ static bool printSpecificCommandHelp(const char* command)
155155 assert (longKey );
156156 if (ffStrEqualsIgnCase (command , yyjson_get_str (longKey )))
157157 {
158- printf ("Usage: --%s\n" , command );
158+ puts (yyjson_get_str (yyjson_obj_get (flagObj , "desc" )));
159+
160+ printf ("%10s: " , "Usage" );
161+ yyjson_val * shortKey = yyjson_obj_get (flagObj , "short" );
162+ if (shortKey )
163+ {
164+ if (!instance .config .display .pipe )
165+ fputs ("\e[1m" , stdout );
166+ printf ("-%s" , yyjson_get_str (shortKey ));
167+ if (!instance .config .display .pipe )
168+ fputs ("\e[m" , stdout );
169+ fputs (", " , stdout );
170+ }
171+ if (!instance .config .display .pipe )
172+ fputs ("\e[1m" , stdout );
173+ printf ("--%s" , yyjson_get_str (longKey ));
174+ if (!instance .config .display .pipe )
175+ fputs ("\e[m" , stdout );
176+
177+ yyjson_val * argObj = yyjson_obj_get (flagObj , "arg" );
178+ if (argObj )
179+ {
180+ yyjson_val * typeKey = yyjson_obj_get (argObj , "type" );
181+ assert (typeKey );
182+ yyjson_val * optionalKey = yyjson_obj_get (argObj , "optional" );
183+ bool optional = optionalKey && yyjson_get_bool (optionalKey );
184+ putchar (' ' );
185+ if (!instance .config .display .pipe )
186+ fputs ("\e[3m" , stdout );
187+ printf ("<%s%s>" , optional ? "?" : "" , yyjson_get_str (typeKey ));
188+ if (!instance .config .display .pipe )
189+ fputs ("\e[m" , stdout );
190+ putchar ('\n' );
191+
192+ yyjson_val * defaultKey = yyjson_obj_get (argObj , "default" );
193+ if (defaultKey )
194+ {
195+ if (ffStrEqualsIgnCase (yyjson_get_str (typeKey ), "structure" ))
196+ printf ("%10s: %s\n" , "Default" , FASTFETCH_DATATEXT_STRUCTURE );
197+ else if (yyjson_is_bool (defaultKey ))
198+ printf ("%10s: %s\n" , "Default" , yyjson_get_bool (defaultKey ) ? "true" : "false" );
199+ else if (yyjson_is_num (defaultKey ))
200+ printf ("%10s: %g\n" , "Default" , yyjson_get_num (defaultKey ));
201+ else if (yyjson_is_str (defaultKey ))
202+ printf ("%10s: %s\n" , "Default" , yyjson_get_str (defaultKey ));
203+ else
204+ printf ("%10s: Unknown\n" , "Default" );
205+ }
206+
207+ yyjson_val * enumKey = yyjson_obj_get (argObj , "enum" );
208+ if (enumKey )
209+ {
210+ printf ("%10s:\n" , "Options" );
211+ yyjson_val * optKey , * optVal ;
212+ size_t optIdx , optMax ;
213+ yyjson_obj_foreach (enumKey , optIdx , optMax , optKey , optVal )
214+ printf ("%12s: %s\n" , yyjson_get_str (optKey ), yyjson_get_str (optVal ));
215+ }
216+ }
217+ else
218+ putchar ('\n' );
219+
220+ yyjson_val * remarkKey = yyjson_obj_get (flagObj , "remark" );
221+ if (remarkKey )
222+ printf ("%10s: %s\n" , "Remark" , yyjson_get_str (remarkKey ));
223+
159224 return true;
160225 }
161226 }
0 commit comments