@@ -15,20 +15,23 @@ public class AddParentPublisherCommand : Command
1515 /// <summary>
1616 /// Initializes a new instance of the <see cref="AddParentPublisherCommand"/> class.
1717 /// </summary>
18- public AddParentPublisherCommand ( WacsdkCommandConfig config , Option < string > repoOption , Option < string > idOption , Option < string > publisherIdOption )
18+ public AddParentPublisherCommand ( WacsdkCommandConfig config , Option < string > repoOption , Option < string > idOption , Option < string > publisherIdOption , Option < string > roleIdOption , Option < string > roleNameOption , Option < string > roleDescriptionOption )
1919 : base ( "add" , "Adds a parent publisher to the Publisher." )
2020 {
2121 AddOption ( repoOption ) ;
2222 AddOption ( idOption ) ;
2323 AddOption ( publisherIdOption ) ;
24+ AddOption ( roleIdOption ) ;
25+ AddOption ( roleNameOption ) ;
26+ AddOption ( roleDescriptionOption ) ;
2427
25- this . SetHandler ( InvokeAsync , repoOption , idOption , publisherIdOption ) ;
28+ this . SetHandler ( InvokeAsync , repoOption , idOption , publisherIdOption , roleIdOption , roleNameOption , roleDescriptionOption ) ;
2629 this . Config = config ;
2730 }
2831
2932 protected WacsdkCommandConfig Config { get ; init ; }
3033
31- public async Task InvokeAsync ( string repo , string id , string publisherId )
34+ public async Task InvokeAsync ( string repo , string id , string publisherId , string roleId , string roleName , string roleDescription )
3235 {
3336 Guard . IsNotNullOrWhiteSpace ( publisherId ) ;
3437
@@ -40,11 +43,22 @@ public async Task InvokeAsync(string repo, string id, string publisherId)
4043 Logger . LogInformation ( $ "Got { nameof ( publisher . Id ) } : { publisher . Id } ") ;
4144
4245 Logger . LogInformation ( $ "Getting parent publisher") ;
43- var parentPublisher = await GetPublisherByIdAsync ( repo , publisherId , cancellationToken ) ;
44- Logger . LogInformation ( $ "Got { nameof ( parentPublisher . Id ) } : { parentPublisher . Id } ") ;
46+ var childPublisher = await GetPublisherByIdAsync ( repo , publisherId , cancellationToken ) ;
47+ Logger . LogInformation ( $ "Got { nameof ( childPublisher . Id ) } : { childPublisher . Id } ") ;
48+
49+ var role = new Role
50+ {
51+ Id = roleId ,
52+ Name = roleName ,
53+ Description = roleDescription
54+ } ;
55+
56+ var readOnlyPublisher = childPublisher is ModifiablePublisher modifiablePublisher ? modifiablePublisher . InnerPublisher : ( ReadOnlyPublisher ) childPublisher ;
57+
58+ var publisherRole = new ReadOnlyPublisherRole { Role = role , InnerPublisher = readOnlyPublisher } ;
4559
4660 Logger . LogInformation ( $ "Adding parent publisher to collection") ;
47- await publisher . ParentPublishers . AddPublisherAsync ( parentPublisher , cancellationToken ) ;
61+ await publisher . ParentPublishers . AddPublisherAsync ( publisherRole , cancellationToken ) ;
4862
4963 Logger . LogInformation ( $ "Publishing changes") ;
5064 await PublishAsync ( publisher , cancellationToken ) ;
0 commit comments