|
| 1 | +//! # Example: Generating Templates from a Configuration File |
| 2 | +//! |
| 3 | +//! This is an example that demonstrates how to generate template files |
| 4 | +//! based on a configuration file using the `generate_from_config` function. |
| 5 | +//! |
| 6 | +//! ## Usage |
| 7 | +//! |
| 8 | +//! To run this example, make sure you have a valid configuration file at the specified path. |
| 9 | +//! The example allows you to define the file type (e.g., "yaml") and the file path. |
| 10 | +//! It then calls the `generate_from_config` function with the file path and file type as parameters. |
| 11 | +//! |
| 12 | +//! If generation is successful, it does nothing (the template files are created). |
| 13 | +//! If there is an error during generation, it prints an error message. |
| 14 | +//! |
| 15 | +//! ```rust |
| 16 | +//! use libmake::generator::generate_from_config; |
| 17 | +//! |
| 18 | +//! // Define the file path for the configuration file. |
| 19 | +//! let file_path = "./tests/data/mylibrary.yaml"; |
| 20 | +//! |
| 21 | +//! // Define the file type, which is "yaml" in this case. |
| 22 | +//! let file_type = "yaml"; |
| 23 | +//! |
| 24 | +//! // Call the generate_from_config function with the file_path and file_type. |
| 25 | +//! // This function generates template files based on the configuration. |
| 26 | +//! match generate_from_config(file_path, file_type) { |
| 27 | +//! // If generation is successful, do nothing (the template files are created). |
| 28 | +//! Ok(_) => (), |
| 29 | +//! // If there is an error during generation, print an error message. |
| 30 | +//! Err(err) => eprintln!("Error: {}", err), |
| 31 | +//! } |
| 32 | +//! ``` |
| 33 | +
|
1 | 34 | use libmake::generator::generate_from_config;
|
| 35 | + |
2 | 36 | fn main() {
|
| 37 | + // Define the file path for the configuration file. |
3 | 38 | let file_path = "./tests/data/mylibrary.yaml";
|
| 39 | + |
| 40 | + // Define the file type, which is "yaml" in this case. |
4 | 41 | let file_type = "yaml";
|
5 | 42 |
|
6 |
| - generate_from_config(file_path, file_type) |
7 |
| - .expect("Failed to generate the template files"); |
| 43 | + // Call the generate_from_config function with the file_path and file_type. |
| 44 | + // This function generates template files based on the configuration. |
| 45 | + match generate_from_config(file_path, file_type) { |
| 46 | + // If generation is successful, do nothing (the template files are created). |
| 47 | + Ok(_) => (), |
| 48 | + // If there is an error during generation, print an error message. |
| 49 | + Err(err) => eprintln!("Error: {}", err), |
| 50 | + } |
8 | 51 | }
|
0 commit comments