Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mopping up rest of the edgedb CLI command references #1402

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/branch/drop.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::branch::context::Context;
use crate::branch::option::Drop;
use crate::branding::BRANDING_CLI_CMD;
use crate::commands::ExitCode;
use crate::connect::Connection;
use crate::portable::exit_codes;
Expand All @@ -15,7 +16,7 @@ pub async fn main(
if current_branch == options.target_branch {
anyhow::bail!(
"Dropping the currently active branch is not supported, please switch to a \
different branch to drop this one with `edgedb branch switch <branch>`"
different branch to drop this one with `{BRANDING_CLI_CMD} branch switch <branch>`"
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/cli/directory_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ pub fn check_and_warn() {
Ok(None) => {}
Ok(Some(dir)) => {
log::warn!(
"Edgedb CLI no longer uses '{}' to store data \
"{BRANDING_CLI} no longer uses '{}' to store data \
and now uses standard locations of your OS. \
Run `edgedb cli migrate` to update the directory layout.",
Run `{BRANDING_CLI_CMD} cli migrate` to update the directory layout.",
dir.display()
);
}
Expand Down
143 changes: 85 additions & 58 deletions src/cli/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,58 +102,80 @@ pub struct Settings {

fn print_long_description(settings: &Settings) {
println!();
print_markdown!("\
# Welcome to EdgeDB!\n\

print_markdown!(
"\
# Welcome to ${branding}!\n\
\n\
This will install the official EdgeDB command-line tools.\n\
This will install the official ${branding} command-line tools.\n\
\n\
The `edgedb` binary will be placed in the ${dir_kind} bin directory \
The `${cmd}` binary will be placed in the ${dir_kind} bin directory \
located at:\n\
```\n\
${installation_path}\n\
```\n\
\n\
${update_win\n\
This path will then be added to your `PATH` environment variable by \
modifying the `HKEY_CURRENT_USER/Environment/PATH` registry key.\n\
\n\
}\n\
${update_files\n\
This path will then be added to your `PATH` environment variable by \
modifying the profile file${s} located at:\n\
```\n\
${rc_files}\n\
```\n\
\n\
}\n\
${modify_path
Path ${installation_path} should be added to the `PATH` manually \
after installation.\n\
\n\
}\n\
${no_modified\n\
This path is already in your `PATH` environment variable, so no \
profile will be modified.\n\
}\n\
",
dir_kind=if settings.system { "system" } else { "user" },
installation_path=settings.installation_path.display(),
update_win: if cfg!(windows) && settings.modify_path,
update_files: if !cfg!(windows) && settings.modify_path => {
rc_files=settings.rc_files.iter()
.map(|p| p.display().to_string())
.collect::<Vec<_>>()
.join("\n"),
s=if settings.rc_files.len() > 1 { "s" } else { "" },
},
modify_path: if !cfg!(windows) && !settings.modify_path &&
no_dir_in_path(&settings.installation_path)
=> {
installation_path=settings.installation_path.display()
},
no_modified: if !cfg!(windows) && !settings.modify_path &&
!no_dir_in_path(&settings.installation_path),
branding = BRANDING,
cmd = BRANDING_CLI_CMD,
dir_kind = if settings.system { "system" } else { "user" },
installation_path = settings.installation_path.display(),
);

if cfg!(windows) && settings.modify_path {
println!();
print_markdown!(
"\
This path will then be added to your `PATH` environment variable by \
modifying the `HKEY_CURRENT_USER/Environment/PATH` registry key.\n\
\n\
"
);
}

if !cfg!(windows) && settings.modify_path {
let rc_files = settings
.rc_files
.iter()
.map(|p| p.display().to_string())
.collect::<Vec<_>>()
.join("\n");
let s = if settings.rc_files.len() > 1 { "s" } else { "" };
println!();
print_markdown!(
"\
This path will then be added to your `PATH` environment variable by \
modifying the profile file${s} located at:\n\
```\n\
${rc_files}\n\
```\n\
\n\
",
s = s,
rc_files = rc_files,
);
}

if !cfg!(windows) && !settings.modify_path && no_dir_in_path(&settings.installation_path) {
println!();
print_markdown!(
"\
Path `${installation_path}` should be added to the `PATH` manually \
after installation.\n\
\n\
",
installation_path = settings.installation_path.display()
);
}

if !cfg!(windows) && !settings.modify_path && !no_dir_in_path(&settings.installation_path) {
println!();
print_markdown!(
"\
This path is already in your `PATH` environment variable, so no \
profile will be modified.\n\
"
);
}
}

pub fn no_dir_in_path(dir: &Path) -> bool {
Expand Down Expand Up @@ -219,18 +241,20 @@ fn print_post_install_message(settings: &Settings, init_result: anyhow::Result<I
if cfg!(windows) && settings.modify_path {
print_markdown!(
"\
# The EdgeDB command-line tool is now installed!\n\
# The ${name} command-line tool is now installed!\n\
\n\
The `${dir}` directory has been added to your `PATH`. You may\n\
need to reopen the terminal for this change to take effect\n\
and for the `edgedb` command to become available.\
and for the `${cmd}` command to become available.\
",
name = BRANDING,
cmd = BRANDING_CLI_CMD,
dir = settings.installation_path.display(),
);
} else if settings.modify_path {
print_markdown!(
"\
# The EdgeDB command-line tool is now installed!\n\
# The ${name} command-line tool is now installed!\n\
\n\
Your shell profile has been updated with ${dir} in your `PATH`.\n\
It will be configured automatically the next time you open the terminal.\n\
Expand All @@ -240,14 +264,16 @@ fn print_post_install_message(settings: &Settings, init_result: anyhow::Result<I
source \"${env_path}\"\n\
```\
",
name = BRANDING,
dir = settings.installation_path.display(),
env_path = settings.env_file.display(),
);
} else {
print_markdown!(
"\
# The EdgeDB command-line tool is now installed!\
"
# The ${name} command-line tool is now installed!\
",
name = BRANDING,
);
}
if is_zsh() {
Expand Down Expand Up @@ -280,9 +306,10 @@ fn print_post_install_message(settings: &Settings, init_result: anyhow::Result<I
Ok(InitResult::Initialized) => {
print_markdown!(
"\n\
`edgedb` without parameters will automatically\n\
`${cmd}` without parameters will automatically\n\
connect to the initialized project.\n\
"
",
cmd = BRANDING_CLI_CMD
);
}
Ok(InitResult::Refused | InitResult::NonInteractive) => {
Expand Down Expand Up @@ -561,7 +588,7 @@ fn _main(options: &CliInstall) -> anyhow::Result<()> {
);
let q = question::Confirm::new(format!(
"\
Do you want to run `edgedb cli migrate` now to update \
Do you want to run `{BRANDING_CLI_CMD} cli migrate` now to update \
the directory layout?\
"
));
Expand Down Expand Up @@ -658,12 +685,12 @@ pub fn check_executables() {

if exe_path.file_name().unwrap() == BRANDING_CLI_CMD_ALT_FILE {
if new_executable.exists() {
log::warn!("{exe_path:?} is the old name for the {BRANDING_CLI_CMD_FILE} executable. \
Please update your scripts (and muscle memory) to use the new executable at {new_executable:?}.");
log::warn!("`{exe_path:?}` is the old name for the `{BRANDING_CLI_CMD_FILE}` executable. \
Please update your scripts (and muscle memory) to use the new executable at `{new_executable:?}`.");
} else {
log::warn!(
"{exe_path:?} is the old name for the {BRANDING_CLI_CMD_FILE} executable, but \
{BRANDING_CLI_CMD_FILE} does not exist. You may need to reinstall {BRANDING} to fix this."
"`{exe_path:?}` is the old name for the `{BRANDING_CLI_CMD_FILE}` executable, but \
`{BRANDING_CLI_CMD_FILE}` does not exist. You may need to reinstall `{BRANDING}` to fix this."
);
}
}
Expand All @@ -684,8 +711,8 @@ pub fn check_executables() {
match (length_old, length_new) {
(Some(length_old), Some(length_new)) if length_old != length_new => {
log::warn!(
"{old_executable:?} and {new_executable:?} have different sizes. \
You mean need to reinstall {BRANDING}."
"`{old_executable:?}` and `{new_executable:?}` have different sizes. \
You may need to reinstall `{BRANDING}`."
);
}
_ => {}
Expand Down
22 changes: 11 additions & 11 deletions src/cli/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use fn_error_context::context;
use fs_err as fs;
use indicatif::{ProgressBar, ProgressStyle};

use crate::platform::{binary_path, current_exe, home_dir, tmp_file_path};
use crate::platform::{binary_path, current_exe, old_binary_path, tmp_file_path};
use crate::portable::platform;
use crate::portable::repository::{self, download, Channel};
use crate::portable::ver;
Expand Down Expand Up @@ -54,18 +54,18 @@ pub fn can_upgrade() -> bool {
})
}

pub fn old_binary_path() -> anyhow::Result<PathBuf> {
let bin_name = if cfg!(windows) {
"edgedb.exe"
} else {
"edgedb"
};
Ok(home_dir()?.join(".edgedb").join("bin").join(bin_name))
}

fn _can_upgrade(path: &Path) -> anyhow::Result<bool> {
let exe_path = current_exe()?;
Ok(exe_path == path || matches!(old_binary_path(), Ok(old) if exe_path == old))
if exe_path == path {
return Ok(true);
}
let Some(current_bin_path) = exe_path.parent() else {
return Ok(false);
};
let Ok(old_binary_path) = old_binary_path() else {
return Ok(false);
};
Ok(current_bin_path == old_binary_path)
}

#[context("error unpacking {:?} -> {:?}", src, tgt)]
Expand Down
4 changes: 2 additions & 2 deletions src/commands/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io::{stdout, Write};

use anyhow::Context;

use crate::branding::BRANDING;
use crate::branding::{BRANDING, BRANDING_CLI_CMD};
use crate::cloud;
use crate::commands::ExitCode;
use crate::options::{Options, UI};
Expand Down Expand Up @@ -123,7 +123,7 @@ fn _get_local_ui_url(cmd: &UI, cfg: &edgedb_tokio::Config) -> anyhow::Result<Str
log::info!("GET {} returned status code {}", url, status);
print::error!(
"Web UI not served correctly by specified {BRANDING} server. \
Try `edgedb instance logs -I <instance_name>` to see details."
Try `{BRANDING_CLI_CMD} instance logs -I <instance_name>` to see details."
);
return Err(ExitCode::new(3).into());
}
Expand Down
11 changes: 3 additions & 8 deletions src/migrations/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use dissimilar::{diff, Chunk};
use tokio::fs;
use tokio::task::spawn_blocking as unblock;

use crate::branding::BRANDING_CLI_CMD;
use crate::commands::Options;
use crate::connect::Connection;
use crate::error_display::print_query_error;
Expand Down Expand Up @@ -81,10 +82,7 @@ pub async fn edit_no_check(
.filter_map(|p| file_num(&p).map(|n| (n, p)))
.max_by(|(an, _), (bn, _)| an.cmp(bn))
.ok_or_else(|| {
anyhow::anyhow!(
"no migration exists. \
Run `edgedb migration create`"
)
anyhow::anyhow!("no migration exists. Run `{BRANDING_CLI_CMD} migration create`")
})?;

if !options.non_interactive {
Expand Down Expand Up @@ -151,10 +149,7 @@ async fn _edit(
.filter_map(|p| file_num(&p).map(|n| (n, p)))
.max_by(|(an, _), (bn, _)| an.cmp(bn))
.ok_or_else(|| {
anyhow::anyhow!(
"no migration exists. \
Run `edgedb migration create`"
)
anyhow::anyhow!("no migration exists. Run `{BRANDING_CLI_CMD} migration create`")
})?;

if options.non_interactive {
Expand Down
Loading
Loading