10
10
from codegen .cli .commands .init .render import get_success_message
11
11
from codegen .cli .git .url import get_git_organization_and_repo
12
12
from codegen .cli .rich .codeblocks import format_command
13
+ from codegen .cli .utils .constants import ProgrammingLanguage
13
14
from codegen .cli .workspace .initialize_workspace import initialize_codegen
14
15
15
16
16
17
@click .command (name = "init" )
17
18
@click .option ("--repo-name" , type = str , help = "The name of the repository" )
18
19
@click .option ("--organization-name" , type = str , help = "The name of the organization" )
19
20
@click .option ("--fetch-docs" , is_flag = True , help = "Fetch docs and examples (requires auth)" )
20
- def init_command (repo_name : str | None = None , organization_name : str | None = None , fetch_docs : bool = False ):
21
+ @click .option ("--language" , type = click .Choice (["python" , "typescript" ], case_sensitive = False ), help = "Override automatic language detection" )
22
+ def init_command (repo_name : str | None = None , organization_name : str | None = None , fetch_docs : bool = False , language : str | None = None ):
21
23
"""Initialize or update the Codegen folder."""
22
24
# Print a message if not in a git repo
23
25
try :
@@ -31,6 +33,11 @@ def init_command(repo_name: str | None = None, organization_name: str | None = N
31
33
rich .print (format_command ("codegen init" ))
32
34
sys .exit (1 )
33
35
36
+ # Convert language string to enum if provided
37
+ programming_language = None
38
+ if language :
39
+ programming_language = ProgrammingLanguage [language .upper ()]
40
+
34
41
# Only create session if we need to fetch docs
35
42
session = CodegenSession () if fetch_docs else None
36
43
codegen_dir = Path .cwd () / CODEGEN_DIR if not session else session .codegen_dir
@@ -46,11 +53,13 @@ def init_command(repo_name: str | None = None, organization_name: str | None = N
46
53
cwd_org , cwd_repo = get_git_organization_and_repo (session .git_repo )
47
54
session .config .organization_name = session .config .organization_name or cwd_org
48
55
session .config .repo_name = session .config .repo_name or cwd_repo
56
+ if programming_language :
57
+ session .config .programming_language = programming_language
49
58
session .write_config ()
50
59
51
60
action = "Updating" if is_update else "Initializing"
52
- rich .print ("" ) # Add a newline before the spinner
53
- codegen_dir , docs_dir , examples_dir = initialize_codegen (action , session = session , fetch_docs = fetch_docs )
61
+ rich .print ("" )
62
+ codegen_dir , docs_dir , examples_dir = initialize_codegen (action , session = session , fetch_docs = fetch_docs , programming_language = programming_language )
54
63
55
64
# Print success message
56
65
rich .print (f"✅ { action } complete\n " )
0 commit comments