-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix :log-open
when --log
is specified
#7573
Conversation
open-log
should open the correct fileopen-log
should open the correct file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use the same strategy as the config file so we don't need to tote around this log_file parameter on more structs and constructors:
Lines 12 to 27 in 618620b
static CONFIG_FILE: once_cell::sync::OnceCell<PathBuf> = once_cell::sync::OnceCell::new(); | |
pub fn initialize_config_file(specified_file: Option<PathBuf>) { | |
let config_file = specified_file.unwrap_or_else(|| { | |
let config_dir = config_dir(); | |
if !config_dir.exists() { | |
std::fs::create_dir_all(&config_dir).ok(); | |
} | |
config_dir.join("config.toml") | |
}); | |
// We should only initialize this value once. | |
CONFIG_FILE.set(config_file).ok(); | |
} |
Lines 124 to 129 in 618620b
pub fn config_file() -> PathBuf { | |
CONFIG_FILE | |
.get() | |
.map(|path| path.to_path_buf()) | |
.unwrap_or_else(|| config_dir().join("config.toml")) | |
} |
Log file can be customized with `--log` argument, the `open-log` command should respect that. As part of this work, also done some boy-scouting around initialisation of directories, cleaning up and making sure they happen in the same place.
@the-mikedavis really nice! much cleaner, I've also done some boy-scouting around that code, let me know if you are cool with it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we also need an ensure_log_dir
since that may be in a different directory than config (by deafult it is for example). I think it would be fine for those functions to be called in the initialize_ functions since those are only meant to be called once at initialization anyways
Also, updated the getters to `unwrap()` as it seems silly to default again in case the cell is not initialised. If the cell is not initialised it would be a big programming error, as the first thing we do when starting the editor is precisely that.
pub fn config_file() -> PathBuf { | ||
CONFIG_FILE | ||
.get() | ||
.map(|path| path.to_path_buf()) | ||
.unwrap_or_else(|| config_dir().join("config.toml")) | ||
CONFIG_FILE.get().map(|path| path.to_path_buf()).unwrap() | ||
} | ||
|
||
pub fn log_file() -> PathBuf { | ||
LOG_FILE.get().map(|path| path.to_path_buf()).unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was about to write the following here (and the equivalent for the config_file()
)
unwrap_or_else(|| {
initialize_log_file(None)
log_file()
})
But then I really think we should unwrap()
and potentially fail. A failure here means we have seriously broken the initialization steps in the main.rs
, it seems less misleading than re-replicating the initialization of the cell in two places.
open-log
should open the correct file:log-open
when --log
is specified
The command always opened the default log file path. The path can be customized passing the
--log
optional argument. When this is the case theopen-log
command should respect it.