33#
44# Mozilla Public License, version 2.0 (see LICENSE or https://www.mozilla.org/en-US/MPL/2.0/)
55import os
6+ import sys
67from pathlib import Path
78from typing import Union
89
@@ -27,8 +28,21 @@ def plugin_group(ctx):
2728 required = False ,
2829)
2930@click .option ("--template" , "-t" , help = "The template to use." , required = False )
31+ @click .option (
32+ "--vcs-ref" ,
33+ "-r" ,
34+ help = "The VCS ref to use, use 'HEAD' for latest dev template." ,
35+ required = False ,
36+ hidden = True ,
37+ )
3038@click .pass_context
31- def create_plugin (ctx , name : str , path : Union [None , str ], template : Union [None , str ]):
39+ def create_plugin (
40+ ctx ,
41+ name : str ,
42+ path : Union [None , str ],
43+ template : Union [None , str ],
44+ vcs_ref : Union [None , str ] = None ,
45+ ):
3246 """Create a new kiara plugin."""
3347
3448 import sys
@@ -67,6 +81,63 @@ def create_plugin(ctx, name: str, path: Union[None, str], template: Union[None,
6781
6882 if not template :
6983 template = "gh:DHARPA-Project/kiara_plugin_template.git"
70- run_copy (template , full_path , data = data , unsafe = True )
84+ run_copy (template , full_path , data = data , unsafe = True , vcs_ref = vcs_ref )
7185
7286 terminal_print (f"Created new plugin '{ name } ' in: { full_path } " )
87+
88+
89+ @plugin_group .command (name = "update" )
90+ @click .argument ("path" , nargs = 1 , required = False )
91+ @click .option (
92+ "--template" , "-t" , help = "The template to use." , required = False , hidden = True
93+ )
94+ @click .option (
95+ "--vcs-ref" ,
96+ "-r" ,
97+ help = "The VCS ref to use, use 'HEAD' for latest dev template." ,
98+ required = False ,
99+ hidden = True ,
100+ )
101+ @click .pass_context
102+ def update_plugin (
103+ ctx : click .Context ,
104+ path : Union [str , None ],
105+ template : Union [str , None ],
106+ vcs_ref : Union [str , None ],
107+ ):
108+ """Update a kiara plugin."""
109+
110+ from copier import run_update
111+
112+ if not path :
113+ _path = Path .cwd ()
114+ else :
115+ _path = Path (path )
116+
117+ if not _path .exists ():
118+ terminal_print (f"Path '{ path } ' does not exist." )
119+ sys .exit (1 )
120+
121+ if not _path .is_dir ():
122+ terminal_print (f"Path '{ path } ' is not a directory." )
123+ sys .exit (1 )
124+
125+ copier_choice_file = _path / ".copier-answers.yml"
126+ if not copier_choice_file .exists ():
127+ terminal_print (f"No .copier-answers.yml file found in '{ path } '." )
128+ sys .exit (1 )
129+
130+ if not copier_choice_file .is_file ():
131+ terminal_print (f"Copier answers file '{ path } ' is not a file." )
132+ sys .exit (1 )
133+
134+ run_update (
135+ src_path = template ,
136+ dst_path = _path ,
137+ vcs_ref = vcs_ref ,
138+ unsafe = True ,
139+ skip_answered = True ,
140+ overwrite = True ,
141+ )
142+
143+ terminal_print (f"Updating plugin in: { _path } " )
0 commit comments