mod.rs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. use anchor_cli::Files;
  2. use heck::ToSnakeCase;
  3. use std::path::Path; // Import the trait
  4. pub fn create_program_template_single(name: &str, program_path: &Path) -> Files {
  5. let program_id = anchor_cli::rust_template::get_or_create_program_id(name);
  6. let program_name = name.to_snake_case();
  7. vec![(
  8. program_path.join("src").join("lib.rs"),
  9. format!(
  10. include_str!("single.lib.rs.template"),
  11. program_id = program_id,
  12. program_name = program_name
  13. ),
  14. )]
  15. }
  16. /// Create a program with multiple files for instructions, state...
  17. pub fn create_program_template_multiple(name: &str, program_path: &Path) -> Files {
  18. let src_path = program_path.join("src");
  19. let program_id = anchor_cli::rust_template::get_or_create_program_id(name);
  20. let program_name = name.to_snake_case();
  21. vec![
  22. (
  23. src_path.join("lib.rs"),
  24. format!(
  25. include_str!("multiple.lib.rs.template"),
  26. program_id = program_id,
  27. program_name = program_name
  28. ),
  29. ),
  30. (
  31. src_path.join("constants.rs"),
  32. include_str!("constants.rs.template").into(),
  33. ),
  34. (src_path.join("error.rs"), include_str!("error.rs.template").into()),
  35. (
  36. src_path.join("instructions").join("mod.rs"),
  37. include_str!("instructions/mod.rs.template").into(),
  38. ),
  39. (
  40. src_path.join("instructions").join("initialize.rs"),
  41. include_str!("instructions/initialize.rs.template").into(),
  42. ),
  43. (
  44. src_path.join("state").join("mod.rs"),
  45. include_str!("state/mod.rs.template").into(),
  46. ),
  47. ]
  48. }