@@ -35,13 +35,24 @@ use crate::util::desktop::{
3535use crate :: util:: {
3636 CliContext ,
3737 app_not_running_message,
38+ qchat_path,
3839} ;
3940
4041#[ derive( Debug , Subcommand , PartialEq , Eq ) ]
4142pub enum SettingsSubcommands {
4243 /// Open the settings file
4344 Open ,
44- /// List all the settings
45+ /// List settings
46+ List {
47+ /// Show all available settings
48+ #[ arg( long) ]
49+ all : bool ,
50+ /// Format of the output
51+ #[ arg( long, short, value_enum, default_value_t) ]
52+ format : OutputFormat ,
53+ } ,
54+ /// List configured settings
55+ #[ command( hide = true ) ]
4556 All {
4657 /// Format of the output
4758 #[ arg( long, short, value_enum, default_value_t) ]
@@ -60,7 +71,7 @@ pub struct SettingsArgs {
6071 key : Option < String > ,
6172 /// value
6273 value : Option < String > ,
63- /// Delete a value
74+ /// Delete a key (No value needed)
6475 #[ arg( long, short) ]
6576 delete : bool ,
6677 /// Format of the output
@@ -89,25 +100,45 @@ impl SettingsArgs {
89100 bail ! ( "The EDITOR environment variable is not set" )
90101 }
91102 } ,
103+ Some ( SettingsSubcommands :: List { all, format } ) => {
104+ let mut args = vec ! [ "settings" . to_string( ) , "list" . to_string( ) ] ;
105+ if all {
106+ args. push ( "--all" . to_string ( ) ) ;
107+ }
108+ if format != OutputFormat :: default ( ) {
109+ args. push ( "--format" . to_string ( ) ) ;
110+ args. push ( format ! ( "{:?}" , format) . to_lowercase ( ) ) ;
111+ }
112+
113+ let status = tokio:: process:: Command :: new ( qchat_path ( ) ?) . args ( & args) . status ( ) . await ?;
114+
115+ Ok ( if status. success ( ) {
116+ ExitCode :: SUCCESS
117+ } else {
118+ ExitCode :: FAILURE
119+ } )
120+ } ,
92121 Some ( SettingsSubcommands :: All { format } ) => {
93- let settings = fig_settings :: OldSettings :: load ( ) ? . map ( ) . clone ( ) ;
122+ let mut args = vec ! [ "settings" . to_string ( ) , "list" . to_string ( ) ] ;
94123
95- match format {
96- OutputFormat :: Plain => {
97- for ( key, value) in settings {
98- println ! ( "{key} = {value}" ) ;
99- }
100- } ,
101- OutputFormat :: Json => println ! ( "{}" , serde_json:: to_string( & settings) ?) ,
102- OutputFormat :: JsonPretty => {
103- println ! ( "{}" , serde_json:: to_string_pretty( & settings) ?) ;
104- } ,
124+ if format != OutputFormat :: default ( ) {
125+ args. push ( "--format" . to_string ( ) ) ;
126+ args. push ( format ! ( "{:?}" , format) . to_lowercase ( ) ) ;
105127 }
106128
107- Ok ( ExitCode :: SUCCESS )
129+ let status = tokio:: process:: Command :: new ( qchat_path ( ) ?) . args ( & args) . status ( ) . await ?;
130+
131+ Ok ( if status. success ( ) {
132+ ExitCode :: SUCCESS
133+ } else {
134+ ExitCode :: FAILURE
135+ } )
108136 } ,
109137 None => match & self . key {
110138 Some ( key) => match ( & self . value , self . delete ) {
139+ ( Some ( _) , true ) => Err ( eyre:: eyre!(
140+ "the argument '--delete' cannot be used with '[VALUE]'\n Usage: q settings --delete {key}"
141+ ) ) ,
111142 ( None , false ) => match fig_settings:: settings:: get_value ( key) ? {
112143 Some ( value) => {
113144 match self . format {
@@ -161,9 +192,14 @@ impl SettingsArgs {
161192
162193 Ok ( ExitCode :: SUCCESS )
163194 } ,
164- _ => Ok ( ExitCode :: SUCCESS ) ,
165195 } ,
166196 None => {
197+ if self . delete {
198+ return Err ( eyre:: eyre!(
199+ "the argument '--delete' requires a <KEY>\n Usage: q settings --delete <KEY>"
200+ ) ) ;
201+ }
202+
167203 if manifest:: is_minimal ( ) || system_info:: is_remote ( ) {
168204 Cli :: parse_from ( [ CLI_BINARY_NAME , "settings" , "--help" ] ) ;
169205 return Ok ( ExitCode :: SUCCESS ) ;
0 commit comments