Skip to content

Commit 5e11474

Browse files
FroVolodFroVolod
andauthored
feat: Improved usability of NEAR CLI in scripts (#445)
Resolves #437 Running NEAR CLI in the --quiet case: ![Image](https://github.com/user-attachments/assets/071f580c-d701-4719-8eba-c945b3d8e3ec) Running NEAR CLI in the "interactive" case: ![Screenshot 2025-02-04 at 19 16 42](https://github.com/user-attachments/assets/8c675dc5-e8a6-4c5f-a594-700eb0e01309) ![Screenshot 2025-02-04 at 19 17 18](https://github.com/user-attachments/assets/52dae480-be44-412d-90a8-1831c9212f6a) --------- Co-authored-by: FroVolod <frol_off@meta.ua>
1 parent a191b63 commit 5e11474

File tree

54 files changed

+2573
-1577
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2573
-1577
lines changed

.github/workflows/code_style.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
jobs:
66
codestyle:
77
name: Code Style (fmt + clippy)
8-
runs-on: ubuntu-20.04
8+
runs-on: ubuntu-latest
99
steps:
1010
- name: Checkout repository
1111
uses: actions/checkout@v2

docs/GUIDE.en.md

Lines changed: 909 additions & 600 deletions
Large diffs are not rendered by default.

docs/GUIDE.ru.md

Lines changed: 906 additions & 599 deletions
Large diffs are not rendered by default.

src/commands/account/create_account/create_implicit_account/use_auto_generation.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ impl SaveWithUseAutoGenerationContext {
4242
.wrap_err_with(|| format!("Failed to create file: {:?}", file_path))?
4343
.write(buf.as_bytes())
4444
.wrap_err_with(|| format!("Failed to write to file: {:?}", folder_path))?;
45-
eprintln!("\nThe file {:?} was saved successfully", &file_path);
45+
46+
tracing::info!(
47+
parent: &tracing::Span::none(),
48+
"The file {:?} was saved successfully",
49+
&file_path
50+
);
4651

4752
Ok(())
4853
}

src/commands/account/create_account/create_implicit_account/use_ledger.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ impl SaveWithLedgerContext {
6666
.wrap_err_with(|| format!("Failed to create file: {:?}", file_path))?
6767
.write(buf.as_bytes())
6868
.wrap_err_with(|| format!("Failed to write to file: {:?}", file_path))?;
69-
eprintln!("\nThe file {:?} was saved successfully", &file_path);
69+
70+
tracing::info!(
71+
parent: &tracing::Span::none(),
72+
"The file {:?} was saved successfully",
73+
&file_path
74+
);
7075

7176
Ok(())
7277
}

src/commands/account/create_account/create_implicit_account/use_seed_phrase.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ impl SaveWithSeedPhraseContext {
5151
.wrap_err_with(|| format!("Failed to create file: {:?}", file_path))?
5252
.write(buf.as_bytes())
5353
.wrap_err_with(|| format!("Failed to write to file: {:?}", file_path))?;
54-
eprintln!("\nThe file {:?} was saved successfully", &file_path);
54+
55+
tracing::info!(
56+
parent: &tracing::Span::none(),
57+
"The file {:?} was saved successfully",
58+
&file_path
59+
);
5560

5661
Ok(())
5762
}

src/commands/account/create_account/fund_myself_create_account/sign_as/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,15 @@ fn validate_new_account_id(
205205
..
206206
},
207207
),
208-
)) => {
209-
eprintln!("\nServer error.\nIt is currently possible to continue creating an account offline.\nYou can sign and send the created transaction later.");
210-
Ok(())
211-
}
208+
)) => Ok(()),
212209
Err(near_jsonrpc_client::errors::JsonRpcError::TransportError(_)) => {
213-
eprintln!("\nTransport error.\nIt is currently possible to continue creating an account offline.\nYou can sign and send the created transaction later.");
210+
tracing::warn!(
211+
parent: &tracing::Span::none(),
212+
"Transport error.{}",
213+
crate::common::indent_payload(
214+
"\nIt is currently possible to continue creating an account offline.\nYou can sign and send the created transaction later.\n"
215+
)
216+
);
214217
Ok(())
215218
}
216219
Err(err) => {

src/commands/account/create_account/sponsor_by_faucet_service/mod.rs

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ fn print_account_creation_status(
123123
credentials_home_dir: &std::path::Path,
124124
storage_message: String,
125125
) -> crate::CliResult {
126-
eprintln!();
127126
match result {
128127
Ok(response) => {
129128
tracing::info!(
@@ -133,7 +132,13 @@ fn print_account_creation_status(
133132
crate::common::indent_payload(&format!("{:#?}", response))
134133
);
135134
if response.status() >= reqwest::StatusCode::BAD_REQUEST {
136-
eprintln!("WARNING! The new account <{new_account_id}> could not be created successfully.\n{storage_message}\n");
135+
tracing::warn!(
136+
parent: &tracing::Span::none(),
137+
"WARNING!{}",
138+
crate::common::indent_payload(&format!(
139+
"\nThe new account <{new_account_id}> could not be created successfully.\n{storage_message}\n"
140+
))
141+
);
137142
return Err(color_eyre::Report::msg(format!(
138143
"The faucet (helper service) server failed with status code <{}>",
139144
response.status()
@@ -152,23 +157,46 @@ fn print_account_creation_status(
152157
match account_creation_transaction.status {
153158
near_primitives::views::FinalExecutionStatus::SuccessValue(ref value) => {
154159
if value == b"false" {
155-
eprintln!("WARNING! The new account <{new_account_id}> could not be created successfully.\n{storage_message}\n");
160+
tracing::warn!(
161+
parent: &tracing::Span::none(),
162+
"WARNING!{}",
163+
crate::common::indent_payload(&format!(
164+
"\nThe new account <{new_account_id}> could not be created successfully.\n{storage_message}\n"
165+
))
166+
);
156167
} else {
157168
crate::common::update_used_account_list_as_signer(
158169
credentials_home_dir,
159170
new_account_id.as_ref(),
160171
);
161-
eprintln!("New account <{new_account_id}> created successfully.\n{storage_message}\n");
172+
tracing::info!(
173+
parent: &tracing::Span::none(),
174+
"{}",
175+
crate::common::indent_payload(&format!(
176+
"\nNew account <{new_account_id}> created successfully.\n{storage_message}\n"
177+
))
178+
);
162179
}
163-
eprintln!("Transaction ID: {id}\nTo see the transaction in the transaction explorer, please open this url in your browser:\n{path}{id}\n",
164-
id=account_creation_transaction.transaction_outcome.id,
165-
path=network_config.explorer_transaction_url
180+
tracing::info!(
181+
parent: &tracing::Span::none(),
182+
"\n{}",
183+
crate::common::indent_payload(&format!(
184+
"Transaction ID: {id}\nTo see the transaction in the transaction explorer, please open this url in your browser:\n{path}{id}\n",
185+
id=account_creation_transaction.transaction_outcome.id,
186+
path=network_config.explorer_transaction_url
187+
))
166188
);
167189
}
168190
near_primitives::views::FinalExecutionStatus::NotStarted
169191
| near_primitives::views::FinalExecutionStatus::Started => unreachable!(),
170192
near_primitives::views::FinalExecutionStatus::Failure(tx_execution_error) => {
171-
eprintln!("WARNING! The new account <{new_account_id}> could not be created successfully.\n{storage_message}\n");
193+
tracing::warn!(
194+
parent: &tracing::Span::none(),
195+
"WARNING!{}",
196+
crate::common::indent_payload(&format!(
197+
"\nThe new account <{new_account_id}> could not be created successfully.\n{storage_message}\n"
198+
))
199+
);
172200
match tx_execution_error {
173201
near_primitives::errors::TxExecutionError::ActionError(action_error) => {
174202
return crate::common::convert_action_error_to_cli_result(
@@ -194,7 +222,13 @@ fn print_account_creation_status(
194222
"JSON RPC Response:\n{}",
195223
crate::common::indent_payload(&err.to_string())
196224
);
197-
eprintln!("WARNING! The new account <{new_account_id}> could not be created successfully.\n{storage_message}\n");
225+
tracing::warn!(
226+
parent: &tracing::Span::none(),
227+
"WARNING!{}",
228+
crate::common::indent_payload(&format!(
229+
"\nThe new account <{new_account_id}> could not be created successfully.\n{storage_message}\n"
230+
))
231+
);
198232
Err(color_eyre::Report::msg(err.to_string()))
199233
}
200234
}

src/commands/account/create_account/sponsor_by_faucet_service/network/mod.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,28 @@ impl NetworkContext {
3232
.wrap_err("Failed to get network config!")?
3333
.clone();
3434

35-
eprintln!("\nYour transaction:");
36-
eprintln!("{:<13} {}", "signer_id:", &network_config.network_name);
37-
eprintln!("actions:");
38-
eprintln!(
39-
"{:>5} {:<20} {}",
35+
let mut info_str: String = String::new();
36+
info_str.push_str(&format!(
37+
"\n{:<13} {}",
38+
"signer_id:", &network_config.network_name
39+
));
40+
info_str.push_str("\nactions:");
41+
info_str.push_str(&format!(
42+
"\n{:>5} {:<20} {}",
4043
"--", "create account:", &previous_context.new_account_id
41-
);
42-
eprintln!("{:>5} {:<20}", "--", "add access key:");
43-
eprintln!(
44-
"{:>18} {:<13} {}",
44+
));
45+
info_str.push_str(&format!("\n{:>5} {:<20}", "--", "add access key:"));
46+
info_str.push_str(&format!(
47+
"\n{:>18} {:<13} {}",
4548
"", "public key:", &previous_context.public_key
49+
));
50+
info_str.push_str(&format!("\n{:>18} {:<13} FullAccess", "", "permission:"));
51+
info_str.push('\n');
52+
53+
tracing::info!(
54+
"Your transaction:{}",
55+
crate::common::indent_payload(&info_str)
4656
);
47-
eprintln!("{:>18} {:<13} FullAccess", "", "permission:");
48-
eprintln!();
4957

5058
Ok(Self {
5159
new_account_id: previous_context.new_account_id,

src/commands/account/import_account/mod.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,18 @@ pub fn login(
4949

5050
let account_id = loop {
5151
let account_id_from_cli = input_account_id()?;
52-
eprintln!();
5352
if crate::common::verify_account_access_key(
5453
account_id_from_cli.clone(),
5554
public_key.clone(),
5655
network_config.clone(),
5756
)
5857
.is_err()
5958
{
60-
eprintln!("{}", error_message);
59+
tracing::warn!(
60+
parent: &tracing::Span::none(),
61+
"WARNING!{}",
62+
crate::common::indent_payload(error_message)
63+
);
6164

6265
#[derive(strum_macros::Display)]
6366
enum ConfirmOptions {
@@ -126,7 +129,11 @@ fn save_access_key(
126129
public_key_str,
127130
account_id.as_ref(),
128131
)?;
129-
eprintln!("{}", storage_message);
132+
tracing::info!(
133+
parent: &tracing::Span::none(),
134+
"\n{}",
135+
crate::common::indent_payload(&storage_message)
136+
);
130137
return Ok(());
131138
}
132139

@@ -138,6 +145,10 @@ fn save_access_key(
138145
account_id.as_ref(),
139146
)
140147
.wrap_err_with(|| format!("Failed to save a file with access key: {}", public_key_str))?;
141-
eprintln!("{}", storage_message);
148+
tracing::info!(
149+
parent: &tracing::Span::none(),
150+
"\n{}",
151+
crate::common::indent_payload(&storage_message)
152+
);
142153
Ok(())
143154
}

0 commit comments

Comments
 (0)