mirror of
https://github.com/openai/codex.git
synced 2026-11-29 00:00:54 +00:00
cleanup codex code
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
use codex_common::CliConfigOverrides;
|
||||
use codex_common::create_config_summary_entries;
|
||||
use codex_core::config::Config;
|
||||
use codex_core::config::ConfigOverrides;
|
||||
|
||||
const EXIT_CODE_INVALID_CONFIG: i32 = 3;
|
||||
|
||||
pub(crate) fn validate_config(cli_overrides: CliConfigOverrides, should_print: bool) {
|
||||
let cli_overrides = match cli_overrides.parse_overrides() {
|
||||
Ok(overrides) => overrides,
|
||||
Err(err) => {
|
||||
eprintln!("Error parsing -c overrides: {err}");
|
||||
std::process::exit(EXIT_CODE_INVALID_CONFIG);
|
||||
}
|
||||
};
|
||||
|
||||
match Config::load_with_cli_overrides(cli_overrides, ConfigOverrides::default()) {
|
||||
Ok(config) => {
|
||||
if should_print {
|
||||
println!("Current default config settings:");
|
||||
println!("--------------------------------");
|
||||
let entries = create_config_summary_entries(&config);
|
||||
|
||||
for (key, value) in entries {
|
||||
println!("{key}: {value}");
|
||||
}
|
||||
println!("--------------------------------");
|
||||
println!("* Note that various commands may override specific settings. *");
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
if should_print {
|
||||
eprintln!("Config validation error: {err}");
|
||||
}
|
||||
std::process::exit(EXIT_CODE_INVALID_CONFIG);
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
-27
@@ -14,8 +14,6 @@ use codex_cli::login::run_login_with_chatgpt;
|
||||
use codex_cli::login::run_logout;
|
||||
use codex_cli::proto;
|
||||
use codex_common::CliConfigOverrides;
|
||||
use codex_core::config::find_codex_home;
|
||||
use codex_core::config::load_config_from_toml;
|
||||
use codex_exec::Cli as ExecCli;
|
||||
use codex_responses_api_proxy::Args as ResponsesApiProxyArgs;
|
||||
use codex_tui::AppExitInfo;
|
||||
@@ -24,9 +22,11 @@ use owo_colors::OwoColorize;
|
||||
use std::path::PathBuf;
|
||||
use supports_color::Stream;
|
||||
|
||||
mod config_command;
|
||||
mod mcp_cmd;
|
||||
mod pre_main_hardening;
|
||||
|
||||
use crate::config_command::validate_config;
|
||||
use crate::mcp_cmd::McpCli;
|
||||
use crate::proto::ProtoCli;
|
||||
|
||||
@@ -87,8 +87,8 @@ enum Subcommand {
|
||||
/// Resume a previous interactive session (picker by default; use --last to continue the most recent).
|
||||
Resume(ResumeCommand),
|
||||
|
||||
/// Validate the configuration file.
|
||||
Config,
|
||||
/// Loads and validates a command. May support additional behavior in the future.
|
||||
Config(ConfigCommand),
|
||||
|
||||
/// Internal: generate TypeScript protocol bindings.
|
||||
#[clap(hide = true)]
|
||||
@@ -106,6 +106,13 @@ struct CompletionCommand {
|
||||
shell: Shell,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
struct ConfigCommand {
|
||||
/// Skip printing result
|
||||
#[arg(short = 's', default_value_t = false)]
|
||||
silent: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
struct ResumeCommand {
|
||||
/// Conversation/session id (UUID). When provided, resumes this session.
|
||||
@@ -318,30 +325,10 @@ async fn cli_main(codex_linux_sandbox_exe: Option<PathBuf>) -> anyhow::Result<()
|
||||
Some(Subcommand::Completion(completion_cli)) => {
|
||||
print_completion(completion_cli);
|
||||
}
|
||||
Some(Subcommand::Config) => {
|
||||
let cli_overrides = match root_config_overrides.parse_overrides() {
|
||||
Ok(overrides) => overrides,
|
||||
Err(err) => {
|
||||
eprintln!("Error parsing -c overrides: {err}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
Some(Subcommand::Config(config_cli)) => {
|
||||
let ConfigCommand { silent } = config_cli;
|
||||
|
||||
let codex_home = match find_codex_home() {
|
||||
Ok(path) => path,
|
||||
Err(err) => {
|
||||
eprintln!("Error finding codex home: {err}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
match load_config_from_toml(&codex_home, cli_overrides) {
|
||||
Ok(_) => println!("Configuration validated successfully"),
|
||||
Err(err) => {
|
||||
eprintln!("Config validation error: {err}");
|
||||
std::process::exit(3);
|
||||
}
|
||||
}
|
||||
validate_config(root_config_overrides, !silent);
|
||||
}
|
||||
Some(Subcommand::Debug(debug_args)) => match debug_args.cmd {
|
||||
DebugCommand::Seatbelt(mut seatbelt_cli) => {
|
||||
|
||||
@@ -22,7 +22,7 @@ fn config_subcommand_reports_success_for_valid_config() -> Result<()> {
|
||||
|
||||
assert!(output.status.success());
|
||||
let stdout = String::from_utf8(output.stdout)?;
|
||||
assert!(stdout.contains("Configuration validated successfully"));
|
||||
assert!(stdout.contains("Current default config settings"));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -254,15 +254,6 @@ pub fn load_config_as_toml_with_cli_overrides(
|
||||
Ok(cfg)
|
||||
}
|
||||
|
||||
/// Load `config.toml` from `codex_home`, apply CLI overrides, and deserialize
|
||||
/// it into [`ConfigToml`].
|
||||
pub fn load_config_from_toml(
|
||||
codex_home: &Path,
|
||||
cli_overrides: Vec<(String, TomlValue)>,
|
||||
) -> std::io::Result<ConfigToml> {
|
||||
load_config_as_toml_with_cli_overrides(codex_home, cli_overrides)
|
||||
}
|
||||
|
||||
/// Read `CODEX_HOME/config.toml` and return it as a generic TOML value. Returns
|
||||
/// an empty TOML table when the file does not exist.
|
||||
pub fn load_config_as_toml(codex_home: &Path) -> std::io::Result<TomlValue> {
|
||||
|
||||
Reference in New Issue
Block a user