mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-24 21:13:47 +00:00
cli: inline create_ui(), use ? to handle config error
This commit is contained in:
parent
1b45c5fe8e
commit
6586a756c1
4 changed files with 23 additions and 23 deletions
|
@ -17,8 +17,9 @@ use std::path::Path;
|
|||
|
||||
use clap::{FromArgMatches, Subcommand};
|
||||
use git2::Repository;
|
||||
use jujutsu::cli_util::{create_ui, handle_command_result, parse_args, CommandError};
|
||||
use jujutsu::cli_util::{handle_command_result, parse_args, CommandError};
|
||||
use jujutsu::commands::{default_app, run_command};
|
||||
use jujutsu::config::read_config;
|
||||
use jujutsu::ui::Ui;
|
||||
use jujutsu_lib::backend::{
|
||||
Backend, BackendResult, Commit, CommitId, Conflict, ConflictId, FileId, SymlinkId, Tree, TreeId,
|
||||
|
@ -35,6 +36,7 @@ enum CustomCommands {
|
|||
}
|
||||
|
||||
fn run(ui: &mut Ui) -> Result<(), CommandError> {
|
||||
ui.reset(read_config()?);
|
||||
let app = CustomCommands::augment_subcommands(default_app());
|
||||
let (mut command_helper, matches) = parse_args(ui, app, std::env::args_os())?;
|
||||
let mut store_factories = StoreFactories::default();
|
||||
|
@ -62,8 +64,8 @@ fn run(ui: &mut Ui) -> Result<(), CommandError> {
|
|||
|
||||
fn main() {
|
||||
jujutsu::cleanup_guard::init();
|
||||
let (mut ui, result) = create_ui();
|
||||
let result = result.and_then(|()| run(&mut ui));
|
||||
let mut ui = Ui::new();
|
||||
let result = run(&mut ui);
|
||||
let exit_code = handle_command_result(&mut ui, result);
|
||||
ui.finalize_writes();
|
||||
std::process::exit(exit_code);
|
||||
|
|
|
@ -14,9 +14,10 @@
|
|||
|
||||
use clap::{FromArgMatches, Subcommand};
|
||||
use jujutsu::cli_util::{
|
||||
create_ui, handle_command_result, parse_args, short_commit_description, CommandError,
|
||||
handle_command_result, parse_args, short_commit_description, CommandError,
|
||||
};
|
||||
use jujutsu::commands::{default_app, run_command};
|
||||
use jujutsu::config::read_config;
|
||||
use jujutsu::ui::Ui;
|
||||
|
||||
#[derive(clap::Parser, Clone, Debug)]
|
||||
|
@ -33,6 +34,7 @@ struct FrobnicateArgs {
|
|||
}
|
||||
|
||||
fn run(ui: &mut Ui) -> Result<(), CommandError> {
|
||||
ui.reset(read_config()?);
|
||||
let app = CustomCommands::augment_subcommands(default_app());
|
||||
let (command_helper, matches) = parse_args(ui, app, std::env::args_os())?;
|
||||
match CustomCommands::from_arg_matches(&matches) {
|
||||
|
@ -61,8 +63,8 @@ fn run(ui: &mut Ui) -> Result<(), CommandError> {
|
|||
|
||||
fn main() {
|
||||
jujutsu::cleanup_guard::init();
|
||||
let (mut ui, result) = create_ui();
|
||||
let result = result.and_then(|()| run(&mut ui));
|
||||
let mut ui = Ui::new();
|
||||
let result = run(&mut ui);
|
||||
let exit_code = handle_command_result(&mut ui, result);
|
||||
ui.finalize_writes();
|
||||
std::process::exit(exit_code);
|
||||
|
|
|
@ -51,7 +51,6 @@ use jujutsu_lib::workspace::{Workspace, WorkspaceInitError, WorkspaceLoadError};
|
|||
use jujutsu_lib::{dag_walk, file_util, git, revset};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::config::read_config;
|
||||
use crate::formatter::Formatter;
|
||||
use crate::merge_tools::{ConflictResolveError, DiffEditError};
|
||||
use crate::templater::TemplateFormatter;
|
||||
|
@ -102,6 +101,12 @@ impl From<config::ConfigError> for CommandError {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<crate::config::ConfigError> for CommandError {
|
||||
fn from(err: crate::config::ConfigError) -> Self {
|
||||
CommandError::ConfigError(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RewriteRootCommit> for CommandError {
|
||||
fn from(err: RewriteRootCommit) -> Self {
|
||||
user_error(err.to_string())
|
||||
|
@ -1469,19 +1474,6 @@ impl ValueParserFactory for RevisionArg {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn create_ui() -> (Ui, Result<(), CommandError>) {
|
||||
// TODO: We need to do some argument parsing here, at least for things like
|
||||
// --config, and for reading user configs from the repo pointed to by -R.
|
||||
let mut ui = Ui::new();
|
||||
match read_config() {
|
||||
Ok(user_settings) => {
|
||||
ui.reset(user_settings);
|
||||
(ui, Ok(()))
|
||||
}
|
||||
Err(err) => (ui, Err(CommandError::ConfigError(err.to_string()))),
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_aliases(
|
||||
user_settings: &UserSettings,
|
||||
app: &clap::Command,
|
||||
|
@ -1578,6 +1570,8 @@ pub fn parse_args(
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: read user configs from the repo pointed to by -R.
|
||||
|
||||
let string_args = resolve_aliases(ui.settings(), &app, &string_args)?;
|
||||
handle_early_args(ui, &app, &string_args)?;
|
||||
let matches = app.clone().try_get_matches_from(&string_args)?;
|
||||
|
|
|
@ -12,8 +12,9 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use jujutsu::cli_util::{create_ui, handle_command_result, parse_args, CommandError};
|
||||
use jujutsu::cli_util::{handle_command_result, parse_args, CommandError};
|
||||
use jujutsu::commands::{default_app, run_command};
|
||||
use jujutsu::config::read_config;
|
||||
use jujutsu::ui::Ui;
|
||||
use tracing::metadata::LevelFilter;
|
||||
use tracing_subscriber::prelude::*;
|
||||
|
@ -24,6 +25,7 @@ fn run(
|
|||
ui: &mut Ui,
|
||||
reload_log_filter: Handle<EnvFilter, impl tracing::Subscriber>,
|
||||
) -> Result<(), CommandError> {
|
||||
ui.reset(read_config()?);
|
||||
let app = default_app();
|
||||
let (command_helper, matches) = parse_args(ui, app, std::env::args_os())?;
|
||||
if command_helper.global_args().verbose {
|
||||
|
@ -56,8 +58,8 @@ fn main() {
|
|||
.init();
|
||||
|
||||
jujutsu::cleanup_guard::init();
|
||||
let (mut ui, result) = create_ui();
|
||||
let result = result.and_then(|()| run(&mut ui, reload_log_filter));
|
||||
let mut ui = Ui::new();
|
||||
let result = run(&mut ui, reload_log_filter);
|
||||
let exit_code = handle_command_result(&mut ui, result);
|
||||
ui.finalize_writes();
|
||||
std::process::exit(exit_code);
|
||||
|
|
Loading…
Reference in a new issue