@@ -9,6 +9,7 @@ pub(crate) mod checker;
99pub ( crate ) mod checker_configuration;
1010pub ( crate ) mod configuration;
1111pub ( crate ) mod constant_resolver;
12+ pub ( crate ) mod creator;
1213pub ( crate ) mod dependencies;
1314pub ( crate ) mod ignored;
1415pub ( crate ) mod monkey_patch_detection;
@@ -26,10 +27,10 @@ mod reference_extractor;
2627
2728use crate :: packs;
2829use crate :: packs:: pack:: write_pack_to_disk;
29- use crate :: packs:: pack:: Pack ;
3030
3131// Internal imports
3232pub ( crate ) use self :: checker:: Violation ;
33+ use self :: creator:: CreateResult ;
3334pub ( crate ) use self :: pack_set:: PackSet ;
3435pub ( crate ) use self :: parsing:: process_files_with_cache;
3536pub ( crate ) use self :: parsing:: ruby:: experimental:: get_experimental_constant_resolver;
@@ -50,47 +51,18 @@ pub fn greet() {
5051 println ! ( "👋 Hello! Welcome to packs 📦 🔥 🎉 🌈. This tool is under construction." )
5152}
5253
53- fn create ( configuration : & Configuration , name : String ) -> anyhow:: Result < ( ) > {
54- let existing_pack = configuration. pack_set . for_pack ( & name) ;
55- if existing_pack. is_ok ( ) {
56- println ! ( "`{}` already exists!" , & name) ;
57- return Ok ( ( ) ) ;
54+ pub fn create (
55+ configuration : & Configuration ,
56+ name : String ,
57+ ) -> anyhow:: Result < ( ) > {
58+ match creator:: create ( configuration, & name) ? {
59+ CreateResult :: AlreadyExists => {
60+ println ! ( "`{}` already exists!" , & name) ;
61+ }
62+ CreateResult :: Success => {
63+ println ! ( "Successfully created `{}`!" , & name) ;
64+ }
5865 }
59- let new_pack_path =
60- configuration. absolute_root . join ( & name) . join ( "package.yml" ) ;
61-
62- let new_pack = Pack :: from_contents (
63- & new_pack_path,
64- & configuration. absolute_root ,
65- "enforce_dependencies: true" ,
66- PackageTodo :: default ( ) ,
67- ) ?;
68-
69- write_pack_to_disk ( & new_pack) ?;
70-
71- let readme = format ! (
72- "Welcome to `{}`!
73-
74- If you're the author, please consider replacing this file with a README.md, which may contain:
75- - What your pack is and does
76- - How you expect people to use your pack
77- - Example usage of your pack's public API and where to find it
78- - Limitations, risks, and important considerations of usage
79- - How to get in touch with eng and other stakeholders for questions or issues pertaining to this pack
80- - What SLAs/SLOs (service level agreements/objectives), if any, your package provides
81- - When in doubt, keep it simple
82- - Anything else you may want to include!
83-
84- README.md should change as your public API changes.
85-
86- See https://github.com/rubyatscale/packs#readme for more info!" ,
87- new_pack. name
88- ) ;
89-
90- let readme_path = configuration. absolute_root . join ( & name) . join ( "README.md" ) ;
91- std:: fs:: write ( readme_path, readme) . context ( "Failed to write README.md" ) ?;
92-
93- println ! ( "Successfully created `{}`!" , name) ;
9466 Ok ( ( ) )
9567}
9668
0 commit comments