@@ -8,8 +8,9 @@ use env_logger::Env;
88use glob:: Pattern ;
99use nom:: AsBytes ;
1010use rebuilderd_common:: api:: v1:: {
11- ArtifactStatus , BinaryPackage , BuildRestApi , IdentityFilter , OriginFilter , PackageReport ,
12- PackageRestApi , Page , QueueJobRequest , QueueRestApi , Worker , WorkerRestApi ,
11+ ArtifactStatus , BinaryPackage , BuildRestApi , CreateTagRequest , CreateTagRuleRequest ,
12+ IdentityFilter , OriginFilter , PackageReport , PackageRestApi , Page , QueueJobRequest ,
13+ QueueRestApi , TagRestApi , Worker , WorkerRestApi ,
1314} ;
1415use rebuilderd_common:: api:: Client ;
1516use rebuilderd_common:: errors:: * ;
@@ -544,6 +545,81 @@ async fn main() -> Result<()> {
544545 writeln ! ( io:: stderr( ) , "Worker {} not found" , tag_target. name. green( ) ) ?;
545546 }
546547 }
548+ SubCommand :: Tag ( TagCommand :: List ) => {
549+ let tags = client. get_tags ( ) . await ?;
550+ writeln ! ( io:: stdout( ) , "{}" , tags. join( "\n " ) . cyan( ) ) ?;
551+ }
552+ SubCommand :: Tag ( TagCommand :: Create ( tag_target) ) => {
553+ let authenticated_client = client. with_auth_cookie ( ) ?;
554+
555+ authenticated_client
556+ . create_tag ( CreateTagRequest {
557+ tag : tag_target. tag . clone ( ) ,
558+ } )
559+ . await ?;
560+
561+ writeln ! ( io:: stdout( ) , "Tag {} created" , tag_target. tag. cyan( ) ) ?;
562+ }
563+ SubCommand :: Tag ( TagCommand :: Delete ( tag_target) ) => {
564+ let authenticated_client = client. with_auth_cookie ( ) ?;
565+
566+ authenticated_client
567+ . delete_tag ( tag_target. tag . clone ( ) )
568+ . await ?;
569+
570+ writeln ! ( io:: stdout( ) , "Tag {} deleted" , tag_target. tag. cyan( ) ) ?;
571+ }
572+ SubCommand :: Tag ( TagCommand :: Rule ( TagRuleCommand :: List ( tag_target) ) ) => {
573+ writeln ! ( io:: stdout( ) , "ID\t Tag\t Name pattern\t Version pattern" , ) ?;
574+
575+ let tags = if let Some ( tag) = tag_target. tag {
576+ vec ! [ tag]
577+ } else {
578+ client. get_tags ( ) . await ?
579+ } ;
580+
581+ for tag in tags {
582+ let tag_rules = client. get_tag_rules ( tag. clone ( ) ) . await ?;
583+ for tag_rule in tag_rules {
584+ writeln ! (
585+ io:: stdout( ) ,
586+ "{}\t {}\t {}\t {}" ,
587+ tag_rule. id. to_string( ) . yellow( ) ,
588+ tag. cyan( ) ,
589+ tag_rule. name_pattern. green( ) ,
590+ tag_rule. version_pattern. unwrap_or( "" . to_string( ) ) . magenta( )
591+ ) ?;
592+ }
593+ }
594+ }
595+ SubCommand :: Tag ( TagCommand :: Rule ( TagRuleCommand :: Create ( create_tag) ) ) => {
596+ let authenticated_client = client. with_auth_cookie ( ) ?;
597+
598+ let tag_rule = authenticated_client
599+ . create_tag_rule (
600+ create_tag. tag ,
601+ CreateTagRuleRequest {
602+ name_pattern : create_tag. name_pattern ,
603+ version_pattern : create_tag. version_pattern ,
604+ } ,
605+ )
606+ . await ?;
607+
608+ writeln ! (
609+ io:: stdout( ) ,
610+ "Rule created (ID {})" ,
611+ tag_rule. id. to_string( ) . yellow( )
612+ ) ?;
613+ }
614+ SubCommand :: Tag ( TagCommand :: Rule ( TagRuleCommand :: Delete ( tag_rule_target) ) ) => {
615+ let authenticated_client = client. with_auth_cookie ( ) ?;
616+
617+ authenticated_client
618+ . delete_tag_rule ( tag_rule_target. tag , tag_rule_target. rule_id )
619+ . await ?;
620+
621+ writeln ! ( io:: stdout( ) , "Rule deleted" ) ?;
622+ }
547623 SubCommand :: Completions ( completions) => args:: gen_completions ( & completions) ?,
548624 }
549625
0 commit comments