summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 7e317cfb5d04ed973a2b2573161f29496bf53be0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
use clap::{Parser, Subcommand};

mod commands;

#[derive(Parser)]
struct Cli {
		#[clap(subcommand)]
		command: Commands,
		/// Verbose (output subshell commands)
		#[clap(short, long, takes_value = false)]
		verbose: bool
}

// TODO: Rename commands
// replace package to repository?

#[derive(Subcommand)]
enum Commands {
		/// Initialize Godot project for GLAM
		Init {
		},

		/// Install new GLAM package
		InstallPackage {
				/// Package project git
				git_repo: String,
				/// Commit to checkout (default is latest)
				#[clap(short, long, required = false, default_value = "")]
				commit: String,
				/// Don't copy to target folder
				#[clap(short, long, required = false, takes_value = false)]
				no_copy: bool,
		},

		/// Install all packages on .glam file
		Install {
				/// Don't copy to target folder
				#[clap(short, long, required = false, takes_value = false)]
				no_copy: bool,
		},

		/// Update a single GLAM package
		UpdatePackage {
				/// Name of the package to update (default is all packages)
				package_name: String,
				/// Don't copy to target folder
				#[clap(short, long, required = false, takes_value = false)]
				no_copy: bool,
		},

		/// Update all GLAM packages
		Update {
				/// Don't copy to target folder
				#[clap(short, long, required = false, takes_value = false)]
				no_copy: bool,
		},

		/// Remove a GLAM package
		RemovePackage {
				/// Name of the package to remove
				package_name: String,
		},

		/// Apply changes to a package
		Apply {
				/// Names of the package to apply changes to
				package_names: Vec<String>,
				/// Create new package from the specified addon folder (will create a git repo)
				#[clap(short, long, required = false, default_value = "")]
				create_from_addon: String,
		}
}

fn main() {
		let cli = Cli::parse();

		match &cli.command {
				Commands::Init {} => {
						let root = commands::search_project_root();
						commands::initialize_glam_files(&root);
						commands::initialize(&root);
				},

				Commands::InstallPackage {git_repo, commit, no_copy} => {
						let root = commands::search_project_root();
						if commands::check_initialization(&root) {
							commands::install_package(&root, git_repo, commit, !*no_copy, cli.verbose);
						}
				},

				Commands::Install { no_copy } => {
						let root = commands::search_project_root();
						if commands::check_initialization(&root) {
							commands::install_all_packages(&root, cli.verbose, !*no_copy);
						}
				},

				Commands::UpdatePackage { package_name, no_copy } => {
						let root = commands::search_project_root();
						if commands::check_initialization(&root) {
							commands::update_package(&root, &package_name, cli.verbose, !*no_copy);
						}
						
				},

				Commands::Update { no_copy } => {
						let root = commands::search_project_root();
						if commands::check_initialization(&root) {
							commands::update_all_packages(&root, cli.verbose, !*no_copy);
						}
				},

				Commands::RemovePackage {package_name} => {
						let root = commands::search_project_root();
						if commands::check_initialization(&root) {
							commands::remove_package(&root, &package_name, cli.verbose);
						}
				},

				Commands::Apply {package_names, create_from_addon} => {
						let root = commands::search_project_root();
						if commands::check_initialization(&root) {
							for package_name in package_names {
								commands::apply_changes(&root, &package_name, &create_from_addon, cli.verbose);
							}
						}
				},
		}
}