harn_cli/package/package_ops/
entry.rs1use super::*;
2
3pub fn check_package(anchor: Option<&Path>, json: bool) {
4 match check_package_impl(anchor) {
5 Ok(report) => {
6 if json {
7 println!(
8 "{}",
9 serde_json::to_string_pretty(&report)
10 .unwrap_or_else(|error| format!(r#"{{"error":"{error}"}}"#))
11 );
12 } else {
13 print_package_check_report(&report);
14 }
15 if !report.errors.is_empty() {
16 process::exit(1);
17 }
18 }
19 Err(error) => {
20 eprintln!("error: {error}");
21 process::exit(1);
22 }
23 }
24}
25
26pub fn pack_package(anchor: Option<&Path>, output: Option<&Path>, dry_run: bool, json: bool) {
27 match pack_package_impl(anchor, output, dry_run) {
28 Ok(report) => {
29 if json {
30 println!(
31 "{}",
32 serde_json::to_string_pretty(&report)
33 .unwrap_or_else(|error| format!(r#"{{"error":"{error}"}}"#))
34 );
35 } else {
36 print_package_pack_report(&report);
37 }
38 }
39 Err(error) => {
40 eprintln!("error: {error}");
41 process::exit(1);
42 }
43 }
44}
45
46pub fn generate_package_docs(anchor: Option<&Path>, output: Option<&Path>, check: bool) {
47 match generate_package_docs_impl(anchor, output, check) {
48 Ok(path) if check => println!("{} is up to date.", path.display()),
49 Ok(path) => println!("Wrote {}.", path.display()),
50 Err(error) => {
51 eprintln!("error: {error}");
52 process::exit(1);
53 }
54 }
55}
56
57#[allow(clippy::too_many_arguments)]
58pub fn publish_package(
59 anchor: Option<&Path>,
60 dry_run: bool,
61 remote: &str,
62 index_repo: &str,
63 index_path: &Path,
64 registry_name: Option<&str>,
65 skip_index_pr: bool,
66 registry: Option<&str>,
67 json: bool,
68) {
69 let options = PackagePublishOptions {
70 dry_run,
71 remote,
72 index_repo,
73 index_path,
74 registry_name,
75 skip_index_pr,
76 registry,
77 };
78
79 match publish_package_impl(anchor, &options) {
80 Ok(report) => {
81 if json {
82 println!(
83 "{}",
84 serde_json::to_string_pretty(&report)
85 .unwrap_or_else(|error| format!(r#"{{"error":"{error}"}}"#))
86 );
87 } else {
88 if report.dry_run {
89 println!("Publish dry run to {} succeeded.", report.registry);
90 } else {
91 println!("Published {}.", report.tag);
92 }
93 println!("tag: {}", report.tag);
94 println!("sha: {}", report.sha);
95 if let Some(command) = report.tag_command.as_deref() {
96 println!("tag command: {command}");
97 }
98 if let Some(diff) = report.index_diff.as_deref() {
99 println!("\nindex diff:\n{diff}");
100 }
101 if let Some(url) = report.index_pr_url.as_deref() {
102 println!("index PR: {url}");
103 }
104 println!("artifact: {}", report.artifact_dir);
105 println!("files: {}", report.files.len());
106 }
107 }
108 Err(error) => {
109 eprintln!("error: {error}");
110 process::exit(1);
111 }
112 }
113}
114
115#[allow(clippy::too_many_arguments)]
116pub fn publish_rule_package(
117 anchor: Option<&Path>,
118 dry_run: bool,
119 remote: &str,
120 index_repo: &str,
121 index_path: &Path,
122 registry_name: Option<&str>,
123 skip_index_pr: bool,
124 registry: Option<&str>,
125 json: bool,
126) {
127 let options = PackagePublishOptions {
128 dry_run,
129 remote,
130 index_repo,
131 index_path,
132 registry_name,
133 skip_index_pr,
134 registry,
135 };
136
137 match publish_rule_package_impl(anchor, &options) {
138 Ok(report) => {
139 if json {
140 println!(
141 "{}",
142 serde_json::to_string_pretty(&report)
143 .unwrap_or_else(|error| format!(r#"{{"error":"{error}"}}"#))
144 );
145 } else {
146 if report.dry_run {
147 println!(
148 "Rule-pack publish dry run to {} succeeded.",
149 report.registry
150 );
151 } else {
152 println!("Published rule pack {}.", report.tag);
153 }
154 println!("tag: {}", report.tag);
155 println!("sha: {}", report.sha);
156 if let Some(command) = report.tag_command.as_deref() {
157 println!("tag command: {command}");
158 }
159 if let Some(diff) = report.index_diff.as_deref() {
160 println!("\nindex diff:\n{diff}");
161 }
162 if let Some(url) = report.index_pr_url.as_deref() {
163 println!("index PR: {url}");
164 }
165 println!("artifact: {}", report.artifact_dir);
166 println!("files: {}", report.files.len());
167 }
168 }
169 Err(error) => {
170 eprintln!("error: {error}");
171 process::exit(1);
172 }
173 }
174}
175
176pub fn list_packages(json: bool) {
177 match list_packages_impl() {
178 Ok(report) if json => {
179 println!(
180 "{}",
181 serde_json::to_string_pretty(&report)
182 .unwrap_or_else(|error| format!(r#"{{"error":"{error}"}}"#))
183 );
184 }
185 Ok(report) => print_package_list_report(&report),
186 Err(error) => {
187 eprintln!("error: {error}");
188 process::exit(1);
189 }
190 }
191}
192
193pub fn doctor_packages(json: bool) {
194 match doctor_packages_impl() {
195 Ok(report) if json => {
196 println!(
197 "{}",
198 serde_json::to_string_pretty(&report)
199 .unwrap_or_else(|error| format!(r#"{{"error":"{error}"}}"#))
200 );
201 if !report.ok {
202 process::exit(1);
203 }
204 }
205 Ok(report) => {
206 print_package_doctor_report(&report);
207 if !report.ok {
208 process::exit(1);
209 }
210 }
211 Err(error) => {
212 eprintln!("error: {error}");
213 process::exit(1);
214 }
215 }
216}