@@ -226,11 +226,13 @@ def main() -> None:
226226 # build
227227 build_cmd = sub .add_parser ("build" , help = "Full graph build (re-parse all files)" )
228228 build_cmd .add_argument ("--repo" , default = None , help = "Repository root (auto-detected)" )
229+ build_cmd .add_argument ("-q" , "--quiet" , action = "store_true" , help = "Suppress output" )
229230
230231 # update
231232 update_cmd = sub .add_parser ("update" , help = "Incremental update (only changed files)" )
232233 update_cmd .add_argument ("--base" , default = "HEAD~1" , help = "Git diff base (default: HEAD~1)" )
233234 update_cmd .add_argument ("--repo" , default = None , help = "Repository root (auto-detected)" )
235+ update_cmd .add_argument ("-q" , "--quiet" , action = "store_true" , help = "Suppress output" )
234236
235237 # watch
236238 watch_cmd = sub .add_parser ("watch" , help = "Watch for changes and auto-update" )
@@ -239,6 +241,11 @@ def main() -> None:
239241 # status
240242 status_cmd = sub .add_parser ("status" , help = "Show graph statistics" )
241243 status_cmd .add_argument ("--repo" , default = None , help = "Repository root (auto-detected)" )
244+ status_cmd .add_argument ("-q" , "--quiet" , action = "store_true" , help = "Suppress output" )
245+ status_cmd .add_argument (
246+ "--json" , action = "store_true" , dest = "json_output" ,
247+ help = "Output as JSON" ,
248+ )
242249
243250 # visualize
244251 vis_cmd = sub .add_parser ("visualize" , help = "Generate interactive HTML graph visualization" )
@@ -421,43 +428,62 @@ def main() -> None:
421428 try :
422429 if args .command == "build" :
423430 result = full_build (repo_root , store )
424- print (
425- f"Full build: { result ['files_parsed' ]} files, "
426- f"{ result ['total_nodes' ]} nodes, { result ['total_edges' ]} edges"
427- )
428- if result ["errors" ]:
429- print (f"Errors: { len (result ['errors' ])} " )
431+ if not args .quiet :
432+ print (
433+ f"Full build: { result ['files_parsed' ]} files, "
434+ f"{ result ['total_nodes' ]} nodes, { result ['total_edges' ]} edges"
435+ )
436+ if result ["errors" ]:
437+ print (f"Errors: { len (result ['errors' ])} " )
430438
431439 elif args .command == "update" :
432440 result = incremental_update (repo_root , store , base = args .base )
433- print (
434- f"Incremental: { result ['files_updated' ]} files updated, "
435- f"{ result ['total_nodes' ]} nodes, { result ['total_edges' ]} edges"
436- )
441+ if not args .quiet :
442+ print (
443+ f"Incremental: { result ['files_updated' ]} files updated, "
444+ f"{ result ['total_nodes' ]} nodes, { result ['total_edges' ]} edges"
445+ )
437446
438447 elif args .command == "status" :
448+ import json as json_mod
439449 stats = store .get_stats ()
440- print (f"Nodes: { stats .total_nodes } " )
441- print (f"Edges: { stats .total_edges } " )
442- print (f"Files: { stats .files_count } " )
443- print (f"Languages: { ', ' .join (stats .languages )} " )
444- print (f"Last updated: { stats .last_updated or 'never' } " )
445- # Show branch info and warn if stale
446450 stored_branch = store .get_metadata ("git_branch" )
447451 stored_sha = store .get_metadata ("git_head_sha" )
448- if stored_branch :
449- print (f"Built on branch: { stored_branch } " )
450- if stored_sha :
451- print (f"Built at commit: { stored_sha [:12 ]} " )
452452 from .incremental import _git_branch_info
453453 current_branch , current_sha = _git_branch_info (repo_root )
454+ stale_warning = None
454455 if stored_branch and current_branch and stored_branch != current_branch :
455- print (
456- f"WARNING: Graph was built on '{ stored_branch } ' "
456+ stale_warning = (
457+ f"Graph was built on '{ stored_branch } ' "
457458 f"but you are now on '{ current_branch } '. "
458459 f"Run 'code-review-graph build' to rebuild."
459460 )
460461
462+ if getattr (args , "json_output" , False ):
463+ data = {
464+ "nodes" : stats .total_nodes ,
465+ "edges" : stats .total_edges ,
466+ "files" : stats .files_count ,
467+ "languages" : list (stats .languages ),
468+ "last_updated" : stats .last_updated ,
469+ "branch" : stored_branch ,
470+ "commit" : stored_sha [:12 ] if stored_sha else None ,
471+ "stale" : stale_warning ,
472+ }
473+ print (json_mod .dumps (data ))
474+ elif not args .quiet :
475+ print (f"Nodes: { stats .total_nodes } " )
476+ print (f"Edges: { stats .total_edges } " )
477+ print (f"Files: { stats .files_count } " )
478+ print (f"Languages: { ', ' .join (stats .languages )} " )
479+ print (f"Last updated: { stats .last_updated or 'never' } " )
480+ if stored_branch :
481+ print (f"Built on branch: { stored_branch } " )
482+ if stored_sha :
483+ print (f"Built at commit: { stored_sha [:12 ]} " )
484+ if stale_warning :
485+ print (f"WARNING: { stale_warning } " )
486+
461487 elif args .command == "watch" :
462488 watch (repo_root , store )
463489
0 commit comments