@@ -28,13 +28,16 @@ impl DynCommand for Command {
2828 . about ( "Get the current platform profile" ) )
2929 . subcommand ( clap:: Command :: new ( "list" )
3030 . about ( "List all available platform profiles" ) )
31+ . subcommand ( clap:: Command :: new ( "cycle" )
32+ . about ( "Cycle to the next platform profile" ) )
3133 }
3234
3335 fn execute ( & self , m : & clap:: ArgMatches ) -> Result < ( ) > {
3436 match m. subcommand ( ) {
3537 Some ( ( "set" , m) ) => self . profile_set ( m) ,
3638 Some ( ( "get" , m) ) => self . profile_get ( m) ,
3739 Some ( ( "list" , m) ) => self . profile_list ( m) ,
40+ Some ( ( "cycle" , m) ) => self . profile_cycle ( m) ,
3841 _ => unreachable ! ( ) ,
3942 }
4043 }
@@ -104,4 +107,35 @@ impl Command {
104107
105108 Ok ( ( ) )
106109 }
110+
111+ fn profile_cycle ( & self , m : & clap:: ArgMatches ) -> Result < ( ) > {
112+ let dev = sys:: profile:: Device :: open ( )
113+ . context ( "Failed to open platform profile device" ) ?;
114+
115+ let supported = dev. get_supported ( )
116+ . context ( "Failed to get supported platform profiles" ) ?;
117+
118+ if supported. is_empty ( ) {
119+ anyhow:: bail!( "No platform profiles available" ) ;
120+ }
121+
122+ let current_profile = dev. get ( )
123+ . context ( "Failed to get current platform profile" ) ?;
124+
125+ // Find the next profile in the list, wrapping around to the start
126+ let next_profile = supported. iter ( )
127+ . cycle ( )
128+ . skip_while ( |& p| p != & current_profile)
129+ . nth ( 1 )
130+ . unwrap_or ( & supported[ 0 ] ) ;
131+
132+ dev. set ( next_profile)
133+ . context ( "Failed to set platform profile" ) ?;
134+
135+ if !m. get_flag ( "quiet" ) {
136+ println ! ( "Platform profile cycled from '{current_profile}' to '{next_profile}'" ) ;
137+ }
138+
139+ Ok ( ( ) )
140+ }
107141}
0 commit comments