@@ -98,7 +98,7 @@ def _create_snapshot_data(path, project_name):
9898@snapshot .command ('create' )
9999@click .argument ('path' , type = click .Path (exists = True , dir_okay = True ))
100100@click .option ('--project' , '-p' , 'project_name_override' , help = 'Override the project name.' )
101- @click .option ('--format' , '-f' , type = click .Choice (['json ' , 'python-semantic-digest ' , 'go-semantic-digest ' ]), default = 'json ' , help = 'Snapshot format.' )
101+ @click .option ('--format' , '-f' , type = click .Choice (['yaml ' , 'json ' , 'md ' ]), default = 'yaml ' , help = 'Snapshot format.' )
102102@click .option ('--output' , '-o' , type = click .Path (), default = None , help = 'Output file path.' )
103103@click .option ('--compress' , is_flag = True , help = 'Enable compression.' )
104104@click .option ('--language' , '-l' , type = click .Choice (['python' , 'go' , 'shell' , 'java' , 'auto' ]), default = 'auto' , help = 'Language to analyze.' )
@@ -110,82 +110,69 @@ def create(ctx, path, project_name_override, format, output, compress, language)
110110 try :
111111 root_path = Path (path )
112112
113- if format in ['python-semantic-digest' , 'go-semantic-digest' ]:
114- if output is None :
115- output = f"{ root_path .name } _{ language } _semantic_digest.yaml"
113+ if language == 'auto' :
114+ if list (root_path .rglob ("*.py" )):
115+ language = "python"
116+ elif list (root_path .rglob ("*.go" )):
117+ language = "go"
118+ elif list (root_path .rglob ("*.java" )):
119+ language = "java"
120+ elif list (root_path .rglob ("*.sh" )):
121+ language = "shell"
122+ else :
123+ click .echo ("Could not auto-detect language." , err = True )
124+ return
116125
126+ if language in ['python' , 'go' ]:
117127 config = SnapshotConfig ()
118128 builder = None
119-
120- if language == 'auto' :
121- if format == 'python-semantic-digest' :
122- language = 'python'
123- elif format == 'go-semantic-digest' :
124- language = 'go'
125- else :
126- # Fallback for auto-detection if format doesn't imply language
127- if list (root_path .rglob ("*.py" )):
128- language = "python"
129- elif list (root_path .rglob ("*.go" )):
130- language = "go"
131- elif list (root_path .rglob ("*.java" )):
132- language = "java"
133- elif list (root_path .rglob ("*.sh" )):
134- language = "shell"
135- else :
136- click .echo ("Could not auto-detect language." , err = True )
137- return
138-
139- if language == 'python' and format == 'python-semantic-digest' :
129+ if language == 'python' :
140130 builder = PythonSemanticSnapshotBuilder (root_path , config )
141- elif language == 'go' and format == 'go-semantic-digest' :
131+ else : # language == 'go'
142132 builder = GoSemanticSnapshotBuilder (root_path , config )
143- # Preserve other language builders for future use, but they won't be triggered
144- # by the current format options.
145- elif language == 'shell' :
146- builder = ShellSemanticSnapshotBuilder (root_path , config )
147- elif language == 'java' :
148- builder = JavaSemanticSnapshotBuilder (root_path , config )
149- else :
150- click .echo (f"Unsupported language/format combination: { language } /{ format } " , err = True )
151- return
152133
153134 project_snapshot = builder .build ()
154135
155- generator = YAMLGenerator ()
156- generator .export (project_snapshot , Path (output ))
157-
158- click .echo (f"{ language .capitalize ()} semantic digest created at { output } " )
159- return
160-
161- snapshot_data = _create_snapshot_data (path , project_name )
136+ if output is None :
137+ output = f"{ root_path .name } _snapshot.{ format } "
162138
163- if output :
164139 output_path = Path (output )
165140 output_path .parent .mkdir (parents = True , exist_ok = True )
166- # Use model_dump_json for consistency
167- with open (output_path , 'w' , encoding = 'utf-8' ) as f :
168- f .write (snapshot_data .model_dump_json (indent = 2 ))
169141
170- click .echo (f"Snapshot created at { output } " )
171- else :
172- manager = SnapshotVersionManager (SNAPSHOT_DIR , project_name , DEFAULT_SNAPSHOT_CONFIG ['snapshot' ])
142+ if format == 'yaml' :
143+ generator = YAMLGenerator ()
144+ generator .export (project_snapshot , output_path )
145+ elif format == 'json' :
146+ with open (output_path , 'w' , encoding = 'utf-8' ) as f :
147+ json .dump (project_snapshot , f , indent = 2 )
148+ elif format == 'md' :
149+ click .echo ("Markdown format is not yet implemented." , err = True )
150+ return
173151
174- # The format for saving via manager is 'json', not the input format for semantic digests
175- save_format = 'json'
152+ click .echo (f"Snapshot created at { output } " )
176153
177- if compress :
178- snapshot_path = manager . save_snapshot ( snapshot_data , save_format )
154+ else : # Fallback to original snapshot logic for other languages
155+ snapshot_data = _create_snapshot_data ( path , project_name )
179156
180- # Compress the file
181- with open ( snapshot_path , 'rb' ) as f_in :
182- with gzip . open ( f" { snapshot_path } .gz" , 'wb' ) as f_out :
183- f_out . writelines ( f_in )
184- os . remove ( snapshot_path )
185- click .echo (f"Compressed snapshot created at { snapshot_path } .gz " )
157+ if output :
158+ output_path = Path ( output )
159+ output_path . parent . mkdir ( parents = True , exist_ok = True )
160+ with open ( output_path , 'w' , encoding = 'utf-8' ) as f :
161+ f . write ( snapshot_data . model_dump_json ( indent = 2 ) )
162+ click .echo (f"Snapshot created at { output } " )
186163 else :
187- snapshot_path = manager .save_snapshot (snapshot_data , save_format )
188- click .echo (f"Snapshot created at { snapshot_path } " )
164+ manager = SnapshotVersionManager (SNAPSHOT_DIR , project_name , DEFAULT_SNAPSHOT_CONFIG ['snapshot' ])
165+ save_format = 'json'
166+ if compress :
167+ snapshot_path = manager .save_snapshot (snapshot_data , save_format )
168+ with open (snapshot_path , 'rb' ) as f_in :
169+ with gzip .open (f"{ snapshot_path } .gz" , 'wb' ) as f_out :
170+ f_out .writelines (f_in )
171+ os .remove (snapshot_path )
172+ click .echo (f"Compressed snapshot created at { snapshot_path } .gz" )
173+ else :
174+ snapshot_path = manager .save_snapshot (snapshot_data , save_format )
175+ click .echo (f"Snapshot created at { snapshot_path } " )
189176 finally :
190177 audit_logger .log (
191178 AuditEvent (
0 commit comments