77 "strings"
88
99 "github.com/nylas/cli/internal/cli/common"
10- "github.com/nylas/cli/internal/domain"
1110 "github.com/nylas/cli/internal/ports"
1211 "github.com/spf13/cobra"
1312)
@@ -93,30 +92,7 @@ func newConfigShowCmd() *cobra.Command {
9392 return struct {}{}, json .NewEncoder (cmd .OutOrStdout ()).Encode (config )
9493 }
9594
96- _ , _ = common .Bold .Printf ("Configuration: %s\n " , config .Name )
97- fmt .Printf (" ID: %s\n " , common .Cyan .Sprint (config .ID ))
98- fmt .Printf (" Slug: %s\n " , common .Green .Sprint (config .Slug ))
99- fmt .Printf (" Duration: %d minutes\n " , config .Availability .DurationMinutes )
100-
101- if len (config .Participants ) > 0 {
102- fmt .Printf ("\n Participants (%d):\n " , len (config .Participants ))
103- for i , p := range config .Participants {
104- fmt .Printf (" %d. %s <%s>" , i + 1 , p .Name , p .Email )
105- if p .IsOrganizer {
106- fmt .Printf (" %s" , common .Green .Sprint ("(Organizer)" ))
107- }
108- fmt .Println ()
109- }
110- }
111-
112- fmt .Printf ("\n Event Booking:\n " )
113- fmt .Printf (" Title: %s\n " , config .EventBooking .Title )
114- if config .EventBooking .Description != "" {
115- fmt .Printf (" Description: %s\n " , config .EventBooking .Description )
116- }
117- if config .EventBooking .Location != "" {
118- fmt .Printf (" Location: %s\n " , config .EventBooking .Location )
119- }
95+ formatConfigDetails (cmd .OutOrStdout (), config )
12096
12197 return struct {}{}, nil
12298 })
@@ -139,47 +115,56 @@ func newConfigCreateCmd() *cobra.Command {
139115 location string
140116 jsonOutput bool
141117 )
118+ flags := & configFlags {}
142119
143120 cmd := & cobra.Command {
144121 Use : "create" ,
145122 Short : "Create a scheduler configuration" ,
146- Long : "Create a new scheduler configuration (meeting type)." ,
123+ Long : `Create a new scheduler configuration (meeting type).
124+
125+ Use flags for common settings, or --file for full JSON config input.
126+ When both are provided, flags override file values.` ,
127+ Example : ` # Simple inline creation
128+ nylas scheduler configs create --name "Quick Chat" --title "Quick Chat" \
129+ --participants [email protected] --duration 15 130+
131+ # With availability settings
132+ nylas scheduler configs create --name "Product Demo" --title "Demo" \
133+ --participants [email protected] --duration 30 --interval 15 \ 134+ --buffer-before 5 --buffer-after 10 --conferencing-provider "Google Meet"
135+
136+ # From a JSON file
137+ nylas scheduler configs create --file config.json
138+
139+ # File as base, override specific values
140+ nylas scheduler configs create --file config.json --duration 60` ,
147141 RunE : func (cmd * cobra.Command , args []string ) error {
148- // Validate participants
149- if len (participants ) == 0 {
150- return common .NewUserError ("at least one participant email is required" , "Use --participant to specify email addresses" )
151- }
152- for i , p := range participants {
153- p = strings .TrimSpace (p )
154- if p == "" {
155- return fmt .Errorf ("participant email at position %d cannot be empty" , i + 1 )
156- }
157- participants [i ] = p
142+ if err := validateConfigFlags (flags ); err != nil {
143+ return err
158144 }
159145
160- _ , err := common .WithClient (args , func (ctx context.Context , client ports.NylasClient , grantID string ) (struct {}, error ) {
161- // Build participants list
162- var participantsList []domain.ConfigurationParticipant
163- for i , email := range participants {
164- participantsList = append (participantsList , domain.ConfigurationParticipant {
165- Email : email ,
166- IsOrganizer : i == 0 , // First participant is organizer
167- })
146+ if flags .file == "" {
147+ if len (participants ) == 0 {
148+ return common .NewUserError ("at least one participant email is required" , "Use --participants to specify email addresses" )
168149 }
169-
170- req := & domain.CreateSchedulerConfigurationRequest {
171- Name : name ,
172- Participants : participantsList ,
173- Availability : domain.AvailabilityRules {
174- DurationMinutes : duration ,
175- },
176- EventBooking : domain.EventBooking {
177- Title : title ,
178- Description : description ,
179- Location : location ,
180- },
150+ for i , p := range participants {
151+ p = strings .TrimSpace (p )
152+ if p == "" {
153+ return fmt .Errorf ("participant email at position %d cannot be empty" , i + 1 )
154+ }
155+ participants [i ] = p
181156 }
157+ }
158+
159+ req , err := buildCreateRequest (cmd , flags , name , participants , duration , title , description , location )
160+ if err != nil {
161+ return err
162+ }
163+ if err := validateCreateRequest (req ); err != nil {
164+ return err
165+ }
182166
167+ _ , err = common .WithClient (args , func (ctx context.Context , client ports.NylasClient , grantID string ) (struct {}, error ) {
183168 config , err := client .CreateSchedulerConfiguration (ctx , req )
184169 if err != nil {
185170 return struct {}{}, common .WrapCreateError ("configuration" , err )
@@ -201,19 +186,16 @@ func newConfigCreateCmd() *cobra.Command {
201186 },
202187 }
203188
204- cmd .Flags ().StringVar (& name , "name" , "" , "Configuration name (required) " )
189+ cmd .Flags ().StringVar (& name , "name" , "" , "Configuration name" )
205190 cmd .Flags ().StringSliceVar (& participants , "participants" , []string {}, "Participant emails (comma-separated, first is organizer)" )
206191 cmd .Flags ().IntVar (& duration , "duration" , 30 , "Meeting duration in minutes" )
207- cmd .Flags ().StringVar (& title , "title" , "" , "Event title (required) " )
192+ cmd .Flags ().StringVar (& title , "title" , "" , "Event title" )
208193 cmd .Flags ().StringVar (& description , "description" , "" , "Event description" )
209194 cmd .Flags ().StringVar (& location , "location" , "" , "Event location" )
210-
211- _ = cmd .MarkFlagRequired ("name" )
212- _ = cmd .MarkFlagRequired ("participants" )
213- _ = cmd .MarkFlagRequired ("title" )
214-
215195 cmd .Flags ().BoolVar (& jsonOutput , "json" , false , "Output as JSON" )
216196
197+ registerConfigFlags (cmd , flags )
198+
217199 return cmd
218200}
219201
@@ -225,38 +207,42 @@ func newConfigUpdateCmd() *cobra.Command {
225207 description string
226208 jsonOutput bool
227209 )
210+ flags := & configFlags {}
228211
229212 cmd := & cobra.Command {
230213 Use : "update <config-id>" ,
231214 Short : "Update a scheduler configuration" ,
232- Long : "Update an existing scheduler configuration." ,
233- Args : cobra .ExactArgs (1 ),
234- RunE : func (cmd * cobra.Command , args []string ) error {
235- configID := args [0 ]
236- _ , err := common .WithClient (args , func (ctx context.Context , client ports.NylasClient , grantID string ) (struct {}, error ) {
237- req := & domain.UpdateSchedulerConfigurationRequest {}
215+ Long : `Update an existing scheduler configuration.
238216
239- if name != "" {
240- req .Name = & name
241- }
217+ Use flags to set specific fields, or --file for full JSON update.
218+ When both are provided, flags override file values.` ,
219+ Example : ` # Update specific fields
220+ nylas scheduler configs update abc123 --name "Updated Name" --duration 60
242221
243- if cmd .Flags ().Changed ("duration" ) {
244- req .Availability = & domain.AvailabilityRules {
245- DurationMinutes : duration ,
246- }
247- }
222+ # Add buffer times
223+ nylas scheduler configs update abc123 --buffer-before 5 --buffer-after 10
248224
249- if cmd . Flags (). Changed ( "title" ) || cmd . Flags (). Changed ( "description" ) {
250- eventBooking := & domain. EventBooking {}
251- if cmd . Flags (). Changed ( "title" ) {
252- eventBooking . Title = title
253- }
254- if cmd . Flags (). Changed ( "description" ) {
255- eventBooking . Description = description
256- }
257- req . EventBooking = eventBooking
258- }
225+ # From a JSON file
226+ nylas scheduler configs update abc123 --file update.json
227+
228+ # File as base, override specific values
229+ nylas scheduler configs update abc123 --file update.json --duration 45` ,
230+ Args : cobra . ExactArgs ( 1 ),
231+ RunE : func ( cmd * cobra. Command , args [] string ) error {
232+ if err := validateConfigFlags ( flags ); err != nil {
233+ return err
234+ }
259235
236+ configID := args [0 ]
237+ req , err := buildUpdateRequest (cmd , flags , name , duration , title , description )
238+ if err != nil {
239+ return err
240+ }
241+ if err := validateUpdateRequest (req ); err != nil {
242+ return err
243+ }
244+
245+ _ , err = common .WithClient (args , func (ctx context.Context , client ports.NylasClient , grantID string ) (struct {}, error ) {
260246 config , err := client .UpdateSchedulerConfiguration (ctx , configID , req )
261247 if err != nil {
262248 return struct {}{}, common .WrapUpdateError ("configuration" , err )
@@ -280,6 +266,8 @@ func newConfigUpdateCmd() *cobra.Command {
280266 cmd .Flags ().StringVar (& description , "description" , "" , "Event description" )
281267 cmd .Flags ().BoolVar (& jsonOutput , "json" , false , "Output as JSON" )
282268
269+ registerConfigFlags (cmd , flags )
270+
283271 return cmd
284272}
285273
0 commit comments