diff --git a/BoxCLI/BoxCLIInfo.cs b/BoxCLI/BoxCLIInfo.cs index 16a40b23..c60867b0 100644 --- a/BoxCLI/BoxCLIInfo.cs +++ b/BoxCLI/BoxCLIInfo.cs @@ -4,6 +4,6 @@ public class BoxCLIInfo { public const string ProductTitle = "Box CLI"; - public const string Version = "0.2.0"; + public const string Version = "1.0.0"; } } \ No newline at end of file diff --git a/BoxCLI/BoxHome/BoxHomeFiles/BoxDefaultSettings.cs b/BoxCLI/BoxHome/BoxHomeFiles/BoxDefaultSettings.cs index 3dc0bcd8..595f129a 100644 --- a/BoxCLI/BoxHome/BoxHomeFiles/BoxDefaultSettings.cs +++ b/BoxCLI/BoxHome/BoxHomeFiles/BoxDefaultSettings.cs @@ -277,7 +277,6 @@ private string CreateBoxReportsFolder() } else { - System.Console.WriteLine("Found existing box reports folder..."); return path; } } diff --git a/BoxCLI/BoxPlatform/Utilities/BoxCollectionsIterators.cs b/BoxCLI/BoxPlatform/Utilities/BoxCollectionsIterators.cs index 1a8acad8..e32275dd 100644 --- a/BoxCLI/BoxPlatform/Utilities/BoxCollectionsIterators.cs +++ b/BoxCLI/BoxPlatform/Utilities/BoxCollectionsIterators.cs @@ -13,21 +13,21 @@ public class BoxCollectionsIterators : IBoxCollectionsIterators { print(collection.Entries[0]); collection.Entries.RemoveAt(0); - System.Console.Write("Show next? Enter q to quit. "); + Reporter.WriteInformation("Show next? Enter q to quit. "); return System.Console.ReadLine().Trim().ToLower(); } public string PageInConsole(Action print, BoxCollectionMarkerBased collection) where T : class, new() { print(collection.Entries[0]); collection.Entries.RemoveAt(0); - System.Console.Write("Show next? Enter q to quit. "); + Reporter.WriteInformation("Show next? Enter q to quit. "); return System.Console.ReadLine().Trim().ToLower(); } public string PageInConsole(Action print, BoxEventCollection collection) { print(collection.Entries[0]); collection.Entries.RemoveAt(0); - System.Console.Write("Show next? Enter q to quit. "); + Reporter.WriteInformation("Show next? Enter q to quit. "); return System.Console.ReadLine().Trim().ToLower(); } diff --git a/BoxCLI/CommandUtilities/CsvModels/BoxMetadataMap.cs b/BoxCLI/CommandUtilities/CsvModels/BoxMetadataMap.cs index 81e779cf..bcf54ed8 100644 --- a/BoxCLI/CommandUtilities/CsvModels/BoxMetadataMap.cs +++ b/BoxCLI/CommandUtilities/CsvModels/BoxMetadataMap.cs @@ -35,8 +35,6 @@ public bool CanConvertTo(Type type) public object ConvertFromString(TypeConverterOptions options, string text) { - System.Console.WriteLine("Text from file..."); - System.Console.WriteLine(text); return JsonConvert.DeserializeObject>(text); } diff --git a/BoxCLI/CommandUtilities/CsvModels/BoxWebhookMap.cs b/BoxCLI/CommandUtilities/CsvModels/BoxWebhookMap.cs index 42c74db4..f9fbc40a 100644 --- a/BoxCLI/CommandUtilities/CsvModels/BoxWebhookMap.cs +++ b/BoxCLI/CommandUtilities/CsvModels/BoxWebhookMap.cs @@ -21,7 +21,6 @@ public sealed class BoxWebhookTargetMap : CsvClassMap { public BoxWebhookTargetMap() { - System.Console.WriteLine("Mapping target..."); Map(m => m.Id).Name("TargetId"); Map(m => m.Type).Name("TargetType"); } diff --git a/BoxCLI/Commands/BoxBaseCommand.cs b/BoxCLI/Commands/BoxBaseCommand.cs index 78f40b15..87ecfa98 100644 --- a/BoxCLI/Commands/BoxBaseCommand.cs +++ b/BoxCLI/Commands/BoxBaseCommand.cs @@ -60,6 +60,19 @@ protected virtual void CheckForId(string id, CommandLineApplication app, string } } + protected virtual void PrintCollaboration(BoxCollaboration c, bool json = false) + { + if (json) + { + this.OutputJson(c); + return; + } + else + { + this.PrintCollaboration(c); + } + } + protected virtual void PrintCollaboration(BoxCollaboration c) { Reporter.WriteInformation($"Collaboration ID: {c.Id}"); @@ -343,14 +356,12 @@ protected virtual bool WriteMetadataTemplateCollectionResultsToReport(List entity, string fileName, string filePath = "", string fileFormat = "") { - System.Console.WriteLine("Starting writer..."); fileFormat = this.ProcessReportsFileFormat(fileFormat); filePath = this.ProcessReportsFilePathForWriters(filePath, fileName, fileFormat); if (fileFormat == _settings.FILE_FORMAT_JSON) { try { - System.Console.WriteLine("Writing JSON file..."); var converter = new BoxJsonConverter(); File.WriteAllText(filePath, converter.Serialize>(entity)); return true; @@ -388,14 +399,12 @@ protected virtual bool WriteEventListResultsToReport(List en protected virtual bool WriteListResultsToReport(List entity, string fileName, string filePath = "", string fileFormat = "") where T : BoxEntity, new() { - System.Console.WriteLine("Starting writer..."); fileFormat = this.ProcessReportsFileFormat(fileFormat); filePath = this.ProcessReportsFilePathForWriters(filePath, fileName, fileFormat); if (fileFormat == _settings.FILE_FORMAT_JSON) { try { - System.Console.WriteLine("Writing JSON file..."); var converter = new BoxJsonConverter(); var collection = new BoxCollection(); collection.Entries = new List(); @@ -436,14 +445,12 @@ protected virtual bool WriteListResultsToReport(List entity, string fil protected virtual bool WriteOffsetCollectionResultsToReport(BoxCollection entity, string fileName, string filePath = "", string fileFormat = "") where T : BoxEntity, new() { - System.Console.WriteLine("Starting writer..."); fileFormat = this.ProcessReportsFileFormat(fileFormat); filePath = this.ProcessReportsFilePathForWriters(filePath, fileName, fileFormat); if (fileFormat == _settings.FILE_FORMAT_JSON) { try { - System.Console.WriteLine("Writing JSON file..."); var converter = new BoxJsonConverter(); File.WriteAllText(filePath, converter.Serialize>(entity)); return true; @@ -480,14 +487,12 @@ protected virtual bool WriteOffsetCollectionResultsToReport(BoxCollection< protected virtual bool WriteMarkerCollectionResultsToReport(BoxCollectionMarkerBased entity, string fileName, string filePath = "", string fileFormat = "") where T : BoxEntity, new() { - System.Console.WriteLine("Starting writer..."); fileFormat = this.ProcessReportsFileFormat(fileFormat); filePath = this.ProcessReportsFilePathForWriters(filePath, fileName, fileFormat); if (fileFormat == _settings.FILE_FORMAT_JSON) { try { - System.Console.WriteLine("Writing JSON file..."); var converter = new BoxJsonConverter(); File.WriteAllText(filePath, converter.Serialize>(entity)); return true; @@ -599,11 +604,9 @@ protected virtual List ReadFileForIdsAndVersionIds(string path) } else if (fileFormat == _settings.FILE_FORMAT_CSV) { - System.Console.WriteLine("Found csv file..."); using (var fs = File.OpenText(path)) using (var csv = new CsvReader(fs)) { - System.Console.WriteLine("Processing csv..."); csv.Configuration.RegisterClassMap(typeof(M)); return csv.GetRecords().ToList(); } @@ -658,9 +661,7 @@ private string ProcessReportsFileFormat(string fileFormat = "") { if (string.IsNullOrEmpty(fileFormat)) { - System.Console.WriteLine("Finding default file format..."); fileFormat = _settings.GetBoxReportsFileFormatSetting(); - System.Console.WriteLine($"Default file format: {fileFormat}"); } return fileFormat.ToLower(); } diff --git a/BoxCLI/Commands/BoxItemCommandBase.cs b/BoxCLI/Commands/BoxItemCommandBase.cs index 27d1c519..66241870 100644 --- a/BoxCLI/Commands/BoxItemCommandBase.cs +++ b/BoxCLI/Commands/BoxItemCommandBase.cs @@ -74,7 +74,18 @@ protected BoxFileRequest ConfigureFileRequest(string fileId = "", string parentI return fileRequest; } - + protected void PrintFile(BoxFile file, bool json = false) + { + if (json) + { + base.OutputJson(file); + return; + } + else + { + this.PrintFile(file); + } + } protected void PrintFile(BoxFile file) { @@ -82,6 +93,19 @@ protected void PrintFile(BoxFile file) Reporter.WriteInformation($"File Name: {file.Name}"); Reporter.WriteInformation($"File Size: {file.Size}"); } + protected void PrintFolder(BoxFolder folder, bool json) + { + if (json) + { + base.OutputJson(folder); + return; + } + else + { + this.PrintFolder(folder); + } + } + protected void PrintFolder(BoxFolder folder) { Reporter.WriteInformation($"Folder ID: {folder.Id}"); @@ -124,7 +148,6 @@ protected virtual void PrintTask(BoxTask task) protected List ReadCustomFile(string path) { var fileFormat = base.ProcessFileFormatFromPath(path); - System.Console.WriteLine($"File is {fileFormat}"); if (fileFormat == base._settings.FILE_FORMAT_JSON) { using (var fs = File.OpenText(path)) @@ -135,11 +158,9 @@ protected List ReadCustomFile(string path) } else if (fileFormat == base._settings.FILE_FORMAT_CSV) { - System.Console.WriteLine("Found csv file..."); using (var fs = File.OpenText(path)) using (var csv = new CsvReader(fs)) { - System.Console.WriteLine("Processing csv..."); csv.Configuration.RegisterClassMap(typeof(M)); return csv.GetRecords().ToList(); } @@ -237,7 +258,7 @@ protected async Task UploadFile(string path, string parentId = "", stri } } - protected async Task ProcessFileUploadsFromFile(string path, string asUser = "", bool isNewVersion = false) + protected async Task ProcessFileUploadsFromFile(string path, string asUser = "", bool isNewVersion = false, bool json = false) { try { @@ -250,7 +271,7 @@ protected async Task ProcessFileUploadsFromFile(string path, string asUser = "", try { var uploadedFile = await this.UploadFile(path: fileRequest.Path, parentId: fileRequest.Parent.Id, fileName: fileRequest.Name); - this.PrintFile(uploadedFile); + this.PrintFile(uploadedFile, json); } catch (Exception e) { @@ -265,7 +286,7 @@ protected async Task ProcessFileUploadsFromFile(string path, string asUser = "", try { var uploadedFile = await this.UploadFile(path: fileRequest.Path, fileId: fileRequest.Id, fileName: fileRequest.Name, isNewVersion: true); - this.PrintFile(uploadedFile); + this.PrintFile(uploadedFile, json); } catch (Exception e) { diff --git a/BoxCLI/Commands/CollaborationSubCommands/CollaborationAddCommand.cs b/BoxCLI/Commands/CollaborationSubCommands/CollaborationAddCommand.cs index a599dd49..48c91a25 100644 --- a/BoxCLI/Commands/CollaborationSubCommands/CollaborationAddCommand.cs +++ b/BoxCLI/Commands/CollaborationSubCommands/CollaborationAddCommand.cs @@ -79,7 +79,12 @@ private async Task RunCreate() { if (!string.IsNullOrEmpty(_path.Value())) { - await base.ProcessCollaborationsFromFile(_id.Value, _path.Value(), base._t, _asUser.Value()); + var json = false; + if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) + { + json = true; + } + await base.ProcessCollaborationsFromFile(_id.Value, _path.Value(), base._t, _asUser.Value(), json: json); } base.CheckForValue(this._id.Value, this._app, "An ID is required for this command."); var boxClient = base.ConfigureBoxClient(base._asUser.Value()); diff --git a/BoxCLI/Commands/CollaborationSubCommands/CollaborationListCommand.cs b/BoxCLI/Commands/CollaborationSubCommands/CollaborationListCommand.cs index ff58531e..d1edd381 100644 --- a/BoxCLI/Commands/CollaborationSubCommands/CollaborationListCommand.cs +++ b/BoxCLI/Commands/CollaborationSubCommands/CollaborationListCommand.cs @@ -58,12 +58,10 @@ private async Task RunList() BoxCollection saveCollabs; if (base._t == BoxType.file) { - System.Console.WriteLine($"Looking for Collaborations on this file {this._id.Value}..."); saveCollabs = await boxClient.FilesManager.GetCollaborationsAsync(this._id.Value); } else if (base._t == BoxType.folder) { - System.Console.WriteLine($"Looking for Collaborations on this folder {this._id.Value}..."); saveCollabs = await boxClient.FoldersManager.GetCollaborationsAsync(this._id.Value); } else @@ -78,12 +76,10 @@ private async Task RunList() BoxCollection collabs; if (base._t == BoxType.file) { - System.Console.WriteLine($"Looking for Collaborations on this file {this._id.Value}..."); collabs = await boxClient.FilesManager.GetCollaborationsAsync(this._id.Value); } else if (base._t == BoxType.folder) { - System.Console.WriteLine($"Looking for Collaborations on this folder {this._id.Value}..."); collabs = await boxClient.FoldersManager.GetCollaborationsAsync(this._id.Value); } else diff --git a/BoxCLI/Commands/CollaborationSubCommands/CollaborationSubCommandBase.cs b/BoxCLI/Commands/CollaborationSubCommands/CollaborationSubCommandBase.cs index 658efb6c..472fba0b 100644 --- a/BoxCLI/Commands/CollaborationSubCommands/CollaborationSubCommandBase.cs +++ b/BoxCLI/Commands/CollaborationSubCommands/CollaborationSubCommandBase.cs @@ -29,7 +29,7 @@ public override void Configure(CommandLineApplication command) base.Configure(command); } - protected async Task ProcessCollaborationsFromFile(string id, string path, BoxType t, string asUser = "") + protected async Task ProcessCollaborationsFromFile(string id, string path, BoxType t, string asUser = "", bool json = false) { var boxClient = base.ConfigureBoxClient(asUser); if (!string.IsNullOrEmpty(path)) @@ -46,7 +46,7 @@ protected async Task ProcessCollaborationsFromFile(string id, string path, BoxTy collaborationRequest.Item.Type = this._t; } var createdCollaboration = await boxClient.CollaborationsManager.AddCollaborationAsync(collaborationRequest); - this.PrintCollaboration(createdCollaboration); + this.PrintCollaboration(createdCollaboration, json); } } catch (Exception e) diff --git a/BoxCLI/Commands/CollaborationSubCommands/CollaborationUpdateCommand.cs b/BoxCLI/Commands/CollaborationSubCommands/CollaborationUpdateCommand.cs index cbbe3964..9e1d2d3b 100644 --- a/BoxCLI/Commands/CollaborationSubCommands/CollaborationUpdateCommand.cs +++ b/BoxCLI/Commands/CollaborationSubCommands/CollaborationUpdateCommand.cs @@ -69,7 +69,12 @@ private async Task RunUpdate() { if (!string.IsNullOrEmpty(_path.Value())) { - await base.ProcessCollaborationsFromFile(_id.Value, _path.Value(), base._t, _asUser.Value()); + var json = false; + if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) + { + json = true; + } + await base.ProcessCollaborationsFromFile(_id.Value, _path.Value(), base._t, _asUser.Value(), json: json); } base.CheckForValue(this._id.Value, this._app, "A collaboration ID is required for this command."); var boxClient = base.ConfigureBoxClient(base._asUser.Value()); diff --git a/BoxCLI/Commands/ConfigureSubCommands/ConfigureEnvironmentsSubCommands/ConfigureEnvironmentsSetCurrentCommand.cs b/BoxCLI/Commands/ConfigureSubCommands/ConfigureEnvironmentsSubCommands/ConfigureEnvironmentsSetCurrentCommand.cs index f36ad270..a8a76592 100644 --- a/BoxCLI/Commands/ConfigureSubCommands/ConfigureEnvironmentsSubCommands/ConfigureEnvironmentsSetCurrentCommand.cs +++ b/BoxCLI/Commands/ConfigureSubCommands/ConfigureEnvironmentsSubCommands/ConfigureEnvironmentsSetCurrentCommand.cs @@ -47,10 +47,10 @@ private async Task RunSetCurrent() protected virtual void GetCurrent() { var defaultEnv = _environments.GetDefaultEnvironment(); - System.Console.WriteLine("Current default environment:"); - System.Console.WriteLine($"Name: {defaultEnv.Name}"); - System.Console.WriteLine($"Client ID: {defaultEnv.ClientId}"); - System.Console.WriteLine($"Enterprise ID: {defaultEnv.EnterpriseId}"); + Reporter.WriteInformation("Current default environment:"); + Reporter.WriteInformation($"Name: {defaultEnv.Name}"); + Reporter.WriteInformation($"Client ID: {defaultEnv.ClientId}"); + Reporter.WriteInformation($"Enterprise ID: {defaultEnv.EnterpriseId}"); } } } \ No newline at end of file diff --git a/BoxCLI/Commands/ConfigureSubCommands/ConfigureEnvironmentsSubCommands/ConfigureEnvironmentsSubCommandBase.cs b/BoxCLI/Commands/ConfigureSubCommands/ConfigureEnvironmentsSubCommands/ConfigureEnvironmentsSubCommandBase.cs index 6f906d9c..dd786a95 100644 --- a/BoxCLI/Commands/ConfigureSubCommands/ConfigureEnvironmentsSubCommands/ConfigureEnvironmentsSubCommandBase.cs +++ b/BoxCLI/Commands/ConfigureSubCommands/ConfigureEnvironmentsSubCommands/ConfigureEnvironmentsSubCommandBase.cs @@ -1,5 +1,6 @@ using System; using BoxCLI.BoxHome; +using BoxCLI.CommandUtilities; using Microsoft.Extensions.CommandLineUtils; namespace BoxCLI.Commands.ConfigureSubCommands.ConfigureEnvironmentsSubCommands @@ -13,10 +14,10 @@ public ConfigureEnvironmentsSubCommandBase(IBoxHome boxHome) : base(boxHome) protected virtual void GetCurrent() { var defaultEnv = _environments.GetDefaultEnvironment(); - System.Console.WriteLine("Current default environment:"); - System.Console.WriteLine($"Name: {defaultEnv.Name}"); - System.Console.WriteLine($"Client ID: {defaultEnv.ClientId}"); - System.Console.WriteLine($"Enterprise ID: {defaultEnv.EnterpriseId}"); + Reporter.WriteInformation("Current default environment:"); + Reporter.WriteInformation($"Name: {defaultEnv.Name}"); + Reporter.WriteInformation($"Client ID: {defaultEnv.ClientId}"); + Reporter.WriteInformation($"Enterprise ID: {defaultEnv.EnterpriseId}"); } } } \ No newline at end of file diff --git a/BoxCLI/Commands/EventSubCommands/EventSubCommandBase.cs b/BoxCLI/Commands/EventSubCommands/EventSubCommandBase.cs index aa200896..fb169c35 100644 --- a/BoxCLI/Commands/EventSubCommands/EventSubCommandBase.cs +++ b/BoxCLI/Commands/EventSubCommands/EventSubCommandBase.cs @@ -55,7 +55,6 @@ protected async virtual Task PollEnterpriseEvents() var nextStream = events.NextStreamPosition; while (true) { - System.Console.WriteLine($"Trying stream postion: {nextStream}"); nextStream = await PollForMoreEnterpriseEvents(nextStream); } } diff --git a/BoxCLI/Commands/FileSubCommand/FileUploadCommand.cs b/BoxCLI/Commands/FileSubCommand/FileUploadCommand.cs index e7ea573e..b2f26234 100644 --- a/BoxCLI/Commands/FileSubCommand/FileUploadCommand.cs +++ b/BoxCLI/Commands/FileSubCommand/FileUploadCommand.cs @@ -54,7 +54,12 @@ private async Task RunUpload() { if (this._bulkPath.HasValue()) { - await base.ProcessFileUploadsFromFile(this._bulkPath.Value(), this._asUser.Value()); + var json = false; + if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) + { + json = true; + } + await base.ProcessFileUploadsFromFile(this._bulkPath.Value(), this._asUser.Value(), json: json); return; } base.CheckForFilePath(this._path.Value, this._app); diff --git a/BoxCLI/Commands/FileVersionSubCommands/FileVersionUploadCommand.cs b/BoxCLI/Commands/FileVersionSubCommands/FileVersionUploadCommand.cs index fdbe6680..6d55f5dc 100644 --- a/BoxCLI/Commands/FileVersionSubCommands/FileVersionUploadCommand.cs +++ b/BoxCLI/Commands/FileVersionSubCommands/FileVersionUploadCommand.cs @@ -55,8 +55,12 @@ private async Task RunUpload() { if (this._bulkPath.HasValue()) { - Reporter.WriteInformation("Using bulk for new file versions..."); - await base.ProcessFileUploadsFromFile(this._bulkPath.Value(), this._asUser.Value(), true); + var json = false; + if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) + { + json = true; + } + await base.ProcessFileUploadsFromFile(this._bulkPath.Value(), this._asUser.Value(), true, json: json); return; } base.CheckForFileId(this._fileId.Value, this._app); diff --git a/BoxCLI/Commands/FolderSubCommands/FolderCreateCommand.cs b/BoxCLI/Commands/FolderSubCommands/FolderCreateCommand.cs index 6b1fa31f..8e5f245a 100644 --- a/BoxCLI/Commands/FolderSubCommands/FolderCreateCommand.cs +++ b/BoxCLI/Commands/FolderSubCommands/FolderCreateCommand.cs @@ -57,8 +57,13 @@ protected async Task RunCreate() { if (this._bulkPath.HasValue()) { + var json = false; + if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) + { + json = true; + } await this.CreateFoldersFromFile(this._bulkPath.Value(), base._asUser.Value(), this._save.HasValue(), - this._filePath.Value(), this._fileFormat.Value()); + this._filePath.Value(), this._fileFormat.Value(), json: json); return; } base.CheckForParentId(this._parentFolderId.Value, this._app); diff --git a/BoxCLI/Commands/FolderSubCommands/FolderSubCommandBase.cs b/BoxCLI/Commands/FolderSubCommands/FolderSubCommandBase.cs index 1f1701cb..d788f427 100644 --- a/BoxCLI/Commands/FolderSubCommands/FolderSubCommandBase.cs +++ b/BoxCLI/Commands/FolderSubCommands/FolderSubCommandBase.cs @@ -96,7 +96,7 @@ protected async virtual Task UploadFolder(string path, string folderId) } protected async virtual Task CreateFoldersFromFile(string path, string asUser = "", - bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "") + bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "", bool json = false) { var boxClient = base.ConfigureBoxClient(asUser); if (!string.IsNullOrEmpty(path)) @@ -110,7 +110,6 @@ protected async virtual Task CreateFoldersFromFile(string path, string asUser = foreach (var folderRequest in folderRequests) { - Reporter.WriteInformation($"Processing a folder request: {folderRequest.Name}"); BoxFolder createdFolder = null; try { @@ -121,17 +120,15 @@ protected async virtual Task CreateFoldersFromFile(string path, string asUser = Reporter.WriteError("Couldn't create folder..."); Reporter.WriteError(e.Message); } - Reporter.WriteSuccess("Created a folder:"); if (createdFolder != null) { - this.PrintFolder(createdFolder); + this.PrintFolder(createdFolder, json); if (save || !string.IsNullOrEmpty(overrideSavePath) || base._settings.GetAutoSaveSetting()) { saveCreated.Add(createdFolder); } } } - Reporter.WriteInformation("Finished processing updates..."); if (save || !string.IsNullOrEmpty(overrideSavePath) || base._settings.GetAutoSaveSetting()) { var fileFormat = base._settings.GetBoxReportsFileFormatSetting(); @@ -150,13 +147,12 @@ protected async virtual Task CreateFoldersFromFile(string path, string asUser = } catch (Exception e) { - System.Console.WriteLine(e.Message); Reporter.WriteError(e.Message); } } protected async virtual Task UpdateFoldersFromFile(string path, string asUser = "", - bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "") + bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "", bool json = false) { var boxClient = base.ConfigureBoxClient(asUser); if (!string.IsNullOrEmpty(path)) @@ -170,7 +166,6 @@ protected async virtual Task UpdateFoldersFromFile(string path, string asUser = foreach (var folderRequest in folderRequests) { - Reporter.WriteInformation($"Processing a folder request: {folderRequest.Name}"); BoxFolder updatedFolder = null; try { @@ -181,17 +176,15 @@ protected async virtual Task UpdateFoldersFromFile(string path, string asUser = Reporter.WriteError("Couldn't update folder..."); Reporter.WriteError(e.Message); } - Reporter.WriteSuccess("Updated a folder:"); if (updatedFolder != null) { - this.PrintFolder(updatedFolder); + this.PrintFolder(updatedFolder, json); if (save || !string.IsNullOrEmpty(overrideSavePath) || base._settings.GetAutoSaveSetting()) { saveUpdated.Add(updatedFolder); } } } - Reporter.WriteInformation("Finished processing updates..."); if (save || !string.IsNullOrEmpty(overrideSavePath) || base._settings.GetAutoSaveSetting()) { var fileFormat = base._settings.GetBoxReportsFileFormatSetting(); @@ -210,7 +203,6 @@ protected async virtual Task UpdateFoldersFromFile(string path, string asUser = } catch (Exception e) { - System.Console.WriteLine(e.Message); Reporter.WriteError(e.Message); } } diff --git a/BoxCLI/Commands/FolderSubCommands/FolderUpdateCommand.cs b/BoxCLI/Commands/FolderSubCommands/FolderUpdateCommand.cs index 25ef5603..84920022 100644 --- a/BoxCLI/Commands/FolderSubCommands/FolderUpdateCommand.cs +++ b/BoxCLI/Commands/FolderSubCommands/FolderUpdateCommand.cs @@ -85,8 +85,13 @@ private async Task RunUpdate() { if (this._bulkFilePath.HasValue()) { + var json = false; + if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) + { + json = true; + } await this.UpdateFoldersFromFile(this._bulkFilePath.Value(), base._asUser.Value(), this._save.HasValue(), - this._filePath.Value(), this._fileFormat.Value()); + this._filePath.Value(), this._fileFormat.Value(), json: json); return; } base.CheckForId(this._folderId.Value, this._app); diff --git a/BoxCLI/Commands/GroupSubCommands/GroupCreateCommand.cs b/BoxCLI/Commands/GroupSubCommands/GroupCreateCommand.cs index 01046d5c..f9778209 100644 --- a/BoxCLI/Commands/GroupSubCommands/GroupCreateCommand.cs +++ b/BoxCLI/Commands/GroupSubCommands/GroupCreateCommand.cs @@ -59,7 +59,12 @@ private async Task RunCreate() { if (this._bulkPath.HasValue()) { - await base.CreateGroupsFromFile(this._bulkPath.Value(), this._asUser.Value(), this._save.HasValue()); + var json = false; + if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) + { + json = true; + } + await base.CreateGroupsFromFile(this._bulkPath.Value(), this._asUser.Value(), this._save.HasValue(), json: json); return; } base.CheckForValue(this._name.Value, this._app, "A group name is required for this command"); diff --git a/BoxCLI/Commands/GroupSubCommands/GroupSubCommandBase.cs b/BoxCLI/Commands/GroupSubCommands/GroupSubCommandBase.cs index 8c201ba8..046188e7 100644 --- a/BoxCLI/Commands/GroupSubCommands/GroupSubCommandBase.cs +++ b/BoxCLI/Commands/GroupSubCommands/GroupSubCommandBase.cs @@ -50,6 +50,18 @@ protected virtual string CheckViewMembersLevel(string m) } return m; } + protected virtual void PrintGroup(BoxGroup g, bool json) + { + if (json) + { + base.OutputJson(g); + return; + } + else + { + this.PrintGroup(g); + } + } protected virtual void PrintGroup(BoxGroup g) { Reporter.WriteInformation($"ID: {g.Id}"); @@ -57,7 +69,7 @@ protected virtual void PrintGroup(BoxGroup g) } protected async Task CreateGroupsFromFile(string path, string asUser = "", - bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "") + bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "", bool json = false) { var boxClient = base.ConfigureBoxClient(asUser); if (!string.IsNullOrEmpty(path)) @@ -66,13 +78,11 @@ protected async Task CreateGroupsFromFile(string path, string asUser = "", } try { - Reporter.WriteInformation("Reading file..."); var groupRequests = base.ReadFile(path); List saveCreated = new List(); foreach (var groupRequest in groupRequests) { - Reporter.WriteInformation($"Processing a group request: {groupRequest.Name}"); BoxGroup createdGroup = null; try { @@ -85,15 +95,13 @@ protected async Task CreateGroupsFromFile(string path, string asUser = "", } if (createdGroup != null) { - Reporter.WriteSuccess("Created a group:"); - this.PrintGroup(createdGroup); + this.PrintGroup(createdGroup, json); if (save || !string.IsNullOrEmpty(overrideSavePath) || base._settings.GetAutoSaveSetting()) { saveCreated.Add(createdGroup); } } } - Reporter.WriteInformation("Finished processing groups..."); if (save || !string.IsNullOrEmpty(overrideSavePath) || base._settings.GetAutoSaveSetting()) { var fileFormat = base._settings.GetBoxReportsFileFormatSetting(); diff --git a/BoxCLI/Commands/MetadataSubCommands/MetadataCreateCommand.cs b/BoxCLI/Commands/MetadataSubCommands/MetadataCreateCommand.cs index 26135cf7..4cd5ff26 100644 --- a/BoxCLI/Commands/MetadataSubCommands/MetadataCreateCommand.cs +++ b/BoxCLI/Commands/MetadataSubCommands/MetadataCreateCommand.cs @@ -57,7 +57,12 @@ private async Task RunCreate() { if (this._bulkFilePath.HasValue()) { - await base.AddMetadataToItemFromFile(this._bulkFilePath.Value()); + var json = false; + if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) + { + json = true; + } + await base.AddMetadataToItemFromFile(this._bulkFilePath.Value(), json: json); return; } base.CheckForId(this._id.Value, this._app); diff --git a/BoxCLI/Commands/MetadataSubCommands/MetadataSubCommandBase.cs b/BoxCLI/Commands/MetadataSubCommands/MetadataSubCommandBase.cs index 29c71990..2f6d3f78 100644 --- a/BoxCLI/Commands/MetadataSubCommands/MetadataSubCommandBase.cs +++ b/BoxCLI/Commands/MetadataSubCommands/MetadataSubCommandBase.cs @@ -101,6 +101,18 @@ protected virtual void PrintMetadataCollection(BoxMetadataTemplateCollection md, bool json) + { + if (json) + { + base.OutputJson(md); + return; + } + else + { + this.PrintMetadata(md); + } + } protected virtual void PrintMetadata(Dictionary md) { foreach (var key in md.Keys) @@ -115,8 +127,6 @@ protected virtual List ReadMetadataCsvFile(string filePath) using (var fs = File.OpenText(filePath)) using (var csv = new CsvReader(fs)) { - System.Console.WriteLine("Processing csv..."); - csv.Configuration.RegisterClassMap(typeof(BoxMetadataRequestMap)); allMetadataOnItem = csv.GetRecords().ToList(); } @@ -125,7 +135,7 @@ protected virtual List ReadMetadataCsvFile(string filePath) } protected async virtual Task AddMetadataToItemFromFile(string path, string asUser = "", string type = "", - bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "") + bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "", bool json = false) { var boxClient = base.ConfigureBoxClient(asUser); if (!string.IsNullOrEmpty(path)) @@ -134,13 +144,11 @@ protected async virtual Task AddMetadataToItemFromFile(string path, string asUse } try { - Reporter.WriteInformation("Reading file..."); var metadataRequests = this.ReadMetadataCsvFile(path); var saveCreated = new List(); foreach (var metadataRequest in metadataRequests) { - Reporter.WriteInformation($"Processing a metadata request: {metadataRequest.TemplateKey}"); Dictionary createdMetadata = null; if (metadataRequest.ItemType != null) { @@ -152,11 +160,6 @@ protected async virtual Task AddMetadataToItemFromFile(string path, string asUse } try { - Reporter.WriteInformation("Attempting create metadata..."); - foreach (var kv in metadataRequest.Metadata) - { - Reporter.WriteInformation($"Key: {kv.Key} Value: {kv.Value}"); - } if (type == "file") { createdMetadata = await boxClient.MetadataManager.CreateFileMetadataAsync(metadataRequest.ItemId, metadataRequest.Metadata, metadataRequest.Scope, metadataRequest.TemplateKey); @@ -175,10 +178,9 @@ protected async virtual Task AddMetadataToItemFromFile(string path, string asUse Reporter.WriteError("Couldn't add metadata..."); Reporter.WriteError(e.Message); } - Reporter.WriteSuccess("Added metadata:"); if (createdMetadata != null) { - this.PrintMetadata(createdMetadata); + this.PrintMetadata(createdMetadata, json); if (save || !string.IsNullOrEmpty(overrideSavePath) || base._settings.GetAutoSaveSetting()) { saveCreated.Add(new BoxMetadataForCsv() @@ -192,7 +194,6 @@ protected async virtual Task AddMetadataToItemFromFile(string path, string asUse } } } - Reporter.WriteInformation("Finished processing metadata..."); if (save || !string.IsNullOrEmpty(overrideSavePath) || base._settings.GetAutoSaveSetting()) { var fileFormat = base._settings.GetBoxReportsFileFormatSetting(); @@ -211,7 +212,6 @@ protected async virtual Task AddMetadataToItemFromFile(string path, string asUse } catch (Exception e) { - System.Console.WriteLine(e.Message); Reporter.WriteError(e.Message); } } diff --git a/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateCreateCommand.cs b/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateCreateCommand.cs index e921f708..5ea91c12 100644 --- a/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateCreateCommand.cs +++ b/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateCreateCommand.cs @@ -64,7 +64,12 @@ private async Task RunCreate() { throw new Exception("CSV bulk upload requires 2 files"); } - await base.CreateMetadataTemplatesFromFile(this._bulkFilePaths.Values[0], this._bulkFilePaths.Values[1]); + var json = false; + if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) + { + json = true; + } + await base.CreateMetadataTemplatesFromFile(this._bulkFilePaths.Values[0], this._bulkFilePaths.Values[1], json: json); return; } if (this._bulkFilePath.HasValue()) diff --git a/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateSubCommandBase.cs b/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateSubCommandBase.cs index 71e66797..8e79c581 100644 --- a/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateSubCommandBase.cs +++ b/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateSubCommandBase.cs @@ -160,14 +160,12 @@ protected virtual List ReadMetadataTemplateCsvFile(string f using (var fs = File.OpenText(filePathTemplate)) using (var csv = new CsvReader(fs)) { - System.Console.WriteLine("Processing csv..."); csv.Configuration.RegisterClassMap(typeof(BoxMetadataTemplateMap)); templates = csv.GetRecords().ToList(); } using (var fs = File.OpenText(filePathFields)) using (var csv = new CsvReader(fs)) { - System.Console.WriteLine("Processing csv..."); csv.Configuration.RegisterClassMap(typeof(BoxMetadataTemplateFieldMap)); fields = csv.GetRecords().ToList(); } @@ -205,7 +203,7 @@ protected virtual List ReadMetadataTemplateCsvFile(string f } protected async virtual Task CreateMetadataTemplatesFromFile(string filePath, string filePathFields = "", - bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "") + bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "", bool json = false) { var boxClient = base.ConfigureBoxClient(returnServiceAccount: true); if (!string.IsNullOrEmpty(filePath)) @@ -237,7 +235,6 @@ protected async virtual Task CreateMetadataTemplatesFromFile(string filePath, st foreach (var templateRequest in templateRequests) { - Reporter.WriteInformation($"Processing a metadata template request: {templateRequest.DisplayName}"); BoxMetadataTemplate createdTemplate = null; try { @@ -248,17 +245,15 @@ protected async virtual Task CreateMetadataTemplatesFromFile(string filePath, st Reporter.WriteError("Couldn't create metadata template..."); Reporter.WriteError(e.Message); } - Reporter.WriteSuccess("Created a metadata template:"); if (createdTemplate != null) { - this.PrintMetadataTemplate(createdTemplate); + this.PrintMetadataTemplate(createdTemplate, json); if (save || !string.IsNullOrEmpty(overrideSavePath) || base._settings.GetAutoSaveSetting()) { saveCreated.Add(createdTemplate); } } } - Reporter.WriteInformation("Finished processing metadata templates..."); if (save || !string.IsNullOrEmpty(overrideSavePath) || base._settings.GetAutoSaveSetting()) { var saveFileFormat = base._settings.GetBoxReportsFileFormatSetting(); @@ -283,6 +278,18 @@ protected async virtual Task CreateMetadataTemplatesFromFile(string filePath, st } } + protected virtual void PrintMetadataTemplate(BoxMetadataTemplate mdt, bool json) + { + if (json) + { + base.OutputJson(mdt); + return; + } + else + { + this.PrintMetadataTemplate(mdt); + } + } protected virtual void PrintMetadataTemplate(BoxMetadataTemplate mdt) { Reporter.WriteInformation($"Template Name: {mdt.DisplayName}"); diff --git a/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkCreateCommand.cs b/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkCreateCommand.cs index fa058dc9..2669d12e 100644 --- a/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkCreateCommand.cs +++ b/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkCreateCommand.cs @@ -57,7 +57,13 @@ private async Task RunCreate() { if (!string.IsNullOrEmpty(_path.Value())) { - await base.ProcessSharedLinksFromFile(_id.Value, _path.Value(), base._t, _asUser.Value()); + var json = false; + if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) + { + json = true; + } + await base.ProcessSharedLinksFromFile(_id.Value, _path.Value(), base._t, _asUser.Value(), json: json); + return; } base.CheckForId(this._id.Value, this._app); var boxClient = base.ConfigureBoxClient(base._asUser.Value()); diff --git a/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkSubCommandBase.cs b/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkSubCommandBase.cs index 375507eb..289cf8fc 100644 --- a/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkSubCommandBase.cs +++ b/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkSubCommandBase.cs @@ -27,33 +27,29 @@ public override void Configure(CommandLineApplication command) base.Configure(command); } - protected async Task ProcessSharedLinksFromFile(string id, string path, BoxType t, string asUser = "") + protected async Task ProcessSharedLinksFromFile(string id, string path, BoxType t, string asUser = "", bool json = false) { var boxClient = base.ConfigureBoxClient(asUser); if (!string.IsNullOrEmpty(path)) { path = GeneralUtilities.TranslatePath(path); } - System.Console.WriteLine($"Path: {path}"); try { - System.Console.WriteLine("Reading file..."); var sharedLinkRequests = base.ReadFile(path); foreach (var sharedLinkRequest in sharedLinkRequests) { - System.Console.WriteLine($"Processing a shared link request: {sharedLinkRequest.Access}"); if (t == BoxType.file) { var createdSharedLink = await boxClient.FilesManager.CreateSharedLinkAsync(id, sharedLinkRequest); - this.PrintSharedLink(createdSharedLink.SharedLink); + this.PrintSharedLink(createdSharedLink.SharedLink, json); } else if (t == BoxType.folder) { var createdSharedLink = await boxClient.FoldersManager.CreateSharedLinkAsync(id, sharedLinkRequest); - this.PrintSharedLink(createdSharedLink.SharedLink); + this.PrintSharedLink(createdSharedLink.SharedLink, json); } } - System.Console.WriteLine("Created all shared links..."); } catch (Exception e) { @@ -61,6 +57,18 @@ protected async Task ProcessSharedLinksFromFile(string id, string path, BoxType } } + protected virtual void PrintSharedLink(BoxSharedLink link, bool json) + { + if (json) + { + base.OutputJson(link); + return; + } + else + { + this.PrintSharedLink(link); + } + } protected virtual void PrintSharedLink(BoxSharedLink link) { if (link == null) diff --git a/BoxCLI/Commands/UserSubCommands/UserCreateCommand.cs b/BoxCLI/Commands/UserSubCommands/UserCreateCommand.cs index 8a4efe1f..eb95eba7 100644 --- a/BoxCLI/Commands/UserSubCommands/UserCreateCommand.cs +++ b/BoxCLI/Commands/UserSubCommands/UserCreateCommand.cs @@ -81,7 +81,12 @@ private async Task RunCreate() var boxClient = base.ConfigureBoxClient(returnServiceAccount: true); if (this._path.HasValue()) { - await base.CreateUsersFromFile(this._path.Value(), json: this._json.HasValue()); + var json = false; + if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) + { + json = true; + } + await base.CreateUsersFromFile(this._path.Value(), json: json); return; } base.CheckForValue(this._name.Value, this._app, "A name is required for this command."); diff --git a/BoxCLI/Commands/UserSubCommands/UserSearchCommand.cs b/BoxCLI/Commands/UserSubCommands/UserSearchCommand.cs index df1e8161..6c887977 100644 --- a/BoxCLI/Commands/UserSubCommands/UserSearchCommand.cs +++ b/BoxCLI/Commands/UserSubCommands/UserSearchCommand.cs @@ -69,7 +69,7 @@ private async Task RunSearch(string userName, bool managedOnly = false) { showNext = BoxCollectionsIterators.PageInConsole(base.PrintUserInfo, users); } - System.Console.WriteLine("Finished..."); + Reporter.WriteInformation("Finished..."); return; } if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) @@ -82,7 +82,7 @@ await BoxCollectionsIterators.ListOffsetCollectionToConsole((offset) => { return boxClient.UsersManager.GetEnterpriseUsersAsync(offset: offset, filterTerm: userName); }, base.PrintUserInfo); - System.Console.WriteLine("Finished..."); + Reporter.WriteInformation("Finished..."); } } } \ No newline at end of file diff --git a/BoxCLI/Commands/UserSubCommands/UserSubCommandBase.cs b/BoxCLI/Commands/UserSubCommands/UserSubCommandBase.cs index 993d860a..16102c2d 100644 --- a/BoxCLI/Commands/UserSubCommands/UserSubCommandBase.cs +++ b/BoxCLI/Commands/UserSubCommands/UserSubCommandBase.cs @@ -52,36 +52,49 @@ public UserSubCommandBase(IBoxPlatformServiceBuilder boxPlatformBuilder, IBoxHom }; } + public virtual void PrintUserInfo(BoxUser user, bool json = false) + { + if (json) + { + base.OutputJson(user); + return; + } + else + { + this.PrintUserInfo(user); + } + } + public virtual void PrintUserInfo(BoxUser user) { - System.Console.WriteLine("----Information about this user----"); + Reporter.WriteInformation("----Information about this user----"); if (user.IsPlatformAccessOnly == true) { - System.Console.WriteLine("User is an App User"); + Reporter.WriteInformation("User is an App User"); } if (user.Login.Contains("AutomationUser") && user.Login.Contains("@boxdevedition.com")) { - System.Console.WriteLine("User is a Service Account"); + Reporter.WriteInformation("User is a Service Account"); } - System.Console.WriteLine($"User Id: {user.Id}"); - System.Console.WriteLine($"User Status: {user.Status}"); - System.Console.WriteLine($"User Type: {user.Type}"); - System.Console.WriteLine($"User Name: {user.Name}"); - System.Console.WriteLine($"User Login: {user.Login}"); + Reporter.WriteInformation($"User Id: {user.Id}"); + Reporter.WriteInformation($"User Status: {user.Status}"); + Reporter.WriteInformation($"User Type: {user.Type}"); + Reporter.WriteInformation($"User Name: {user.Name}"); + Reporter.WriteInformation($"User Login: {user.Login}"); if (user.Enterprise != null) { - System.Console.WriteLine($"Enterprise this User Belongs to: {user.Enterprise.Name}"); - System.Console.WriteLine($"Enterprise this User Belongs to: {user.Enterprise.Id}"); - System.Console.WriteLine($"Enterprise this User Belongs to: {user.Enterprise.Type}"); + Reporter.WriteInformation($"Enterprise this User Belongs to: {user.Enterprise.Name}"); + Reporter.WriteInformation($"Enterprise this User Belongs to: {user.Enterprise.Id}"); + Reporter.WriteInformation($"Enterprise this User Belongs to: {user.Enterprise.Type}"); } - System.Console.WriteLine($"User Address: {user.Address}"); - System.Console.WriteLine($"User Phone: {user.Phone}"); - System.Console.WriteLine($"User Language: {user.Language}"); - System.Console.WriteLine($"User Role: {user.Role}"); - System.Console.WriteLine($"User Job Title: {user.JobTitle}"); - System.Console.WriteLine($"User Max Upload Size: {user.MaxUploadSize}"); - System.Console.WriteLine($"User Space Alloted: {user.SpaceAmount}"); - System.Console.WriteLine($"User Space Used: {user.SpaceUsed}"); + Reporter.WriteInformation($"User Address: {user.Address}"); + Reporter.WriteInformation($"User Phone: {user.Phone}"); + Reporter.WriteInformation($"User Language: {user.Language}"); + Reporter.WriteInformation($"User Role: {user.Role}"); + Reporter.WriteInformation($"User Job Title: {user.JobTitle}"); + Reporter.WriteInformation($"User Max Upload Size: {user.MaxUploadSize}"); + Reporter.WriteInformation($"User Space Alloted: {user.SpaceAmount}"); + Reporter.WriteInformation($"User Space Used: {user.SpaceUsed}"); } protected void CheckForUserId(string id, CommandLineApplication app) @@ -116,17 +129,11 @@ protected async Task CreateUsersFromFile(string path, string asUser = "", foreach (var userRequest in userRequests) { var createdUser = await boxClient.UsersManager.CreateEnterpriseUserAsync(userRequest); - if (json) - { - base.OutputJson(createdUser); - continue; - } - PrintUserInfo(createdUser); + PrintUserInfo(createdUser, json); } } catch (Exception e) { - System.Console.WriteLine(e.Message); Reporter.WriteError(e.Message); } } diff --git a/BoxCLI/Commands/WebhooksSubComands/WebhooksCreateCommand.cs b/BoxCLI/Commands/WebhooksSubComands/WebhooksCreateCommand.cs index 8b5080c3..c0c55a97 100644 --- a/BoxCLI/Commands/WebhooksSubComands/WebhooksCreateCommand.cs +++ b/BoxCLI/Commands/WebhooksSubComands/WebhooksCreateCommand.cs @@ -59,7 +59,12 @@ private async Task RunCreate() { if (!string.IsNullOrEmpty(_path.Value())) { - await base.CreateWebhooksFromFile(_path.Value(), _asUser.Value(), this._save.HasValue()); + var json = false; + if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) + { + json = true; + } + await base.CreateWebhooksFromFile(_path.Value(), _asUser.Value(), this._save.HasValue(), json: json); return; } base.CheckForValue(this._id.Value, this._app, "A Box item ID is required for this call."); diff --git a/BoxCLI/Commands/WebhooksSubComands/WebhooksListCommand.cs b/BoxCLI/Commands/WebhooksSubComands/WebhooksListCommand.cs index 9a31dacd..df8863ad 100644 --- a/BoxCLI/Commands/WebhooksSubComands/WebhooksListCommand.cs +++ b/BoxCLI/Commands/WebhooksSubComands/WebhooksListCommand.cs @@ -54,11 +54,8 @@ public async Task RunList() if (_save.HasValue()) { var fileName = $"{base._names.CommandNames.Webhooks}-{base._names.SubCommandNames.List}-{DateTime.Now.ToString(GeneralUtilities.GetDateFormatString())}"; - System.Console.WriteLine("Saving file..."); - System.Console.WriteLine(_fileFormat.Value()); var webhooks = await boxClient.WebhooksManager.GetWebhooksAsync(autoPaginate: true); var saved = base.WriteMarkerCollectionResultsToReport(webhooks, fileName, _path.Value(), _fileFormat.Value()); - System.Console.WriteLine($"File saved: {saved}"); } else if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { diff --git a/BoxCLI/Commands/WebhooksSubComands/WebhooksSubCommandBase.cs b/BoxCLI/Commands/WebhooksSubComands/WebhooksSubCommandBase.cs index d02d43f0..f08adf7c 100644 --- a/BoxCLI/Commands/WebhooksSubComands/WebhooksSubCommandBase.cs +++ b/BoxCLI/Commands/WebhooksSubComands/WebhooksSubCommandBase.cs @@ -28,23 +28,20 @@ public override void Configure(CommandLineApplication command) } protected async Task CreateWebhooksFromFile(string path, string asUser = "", - bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "") + bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "", bool json = false) { var boxClient = base.ConfigureBoxClient(asUser); if (!string.IsNullOrEmpty(path)) { path = GeneralUtilities.TranslatePath(path); } - System.Console.WriteLine($"Path: {path}"); try { - System.Console.WriteLine("Reading file..."); var webhookRequests = base.ReadFile(path); List saveCreated = new List(); foreach (var webhookRequest in webhookRequests) { - Reporter.WriteInformation($"Processing a webhook request: {webhookRequest.Address}"); BoxWebhook createdWebhook = null; try { @@ -55,10 +52,9 @@ protected async Task CreateWebhooksFromFile(string path, string asUser = "", Reporter.WriteError("Couldn't create webhook..."); Reporter.WriteError(e.Message); } - Reporter.WriteSuccess("Created a webhook:"); if (createdWebhook != null) { - this.PrintWebhook(createdWebhook); + this.PrintWebhook(createdWebhook, json); if (save || !string.IsNullOrEmpty(overrideSavePath) || base._settings.GetAutoSaveSetting()) { saveCreated.Add(createdWebhook); @@ -84,29 +80,25 @@ protected async Task CreateWebhooksFromFile(string path, string asUser = "", } catch (Exception e) { - System.Console.WriteLine(e.Message); Reporter.WriteError(e.Message); } } protected async Task UpdateWebhooksFromFile(string path, string asUser = "", - bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "") + bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "", bool json = false) { var boxClient = base.ConfigureBoxClient(asUser); if (!string.IsNullOrEmpty(path)) { path = GeneralUtilities.TranslatePath(path); } - System.Console.WriteLine($"Path: {path}"); try { - System.Console.WriteLine("Reading file..."); var webhookRequests = base.ReadFile(path); List saveUpdated = new List(); foreach (var webhookRequest in webhookRequests) { - Reporter.WriteInformation($"Processing a webhook request: {webhookRequest.Address}"); BoxWebhook updatedWebhook = null; try { @@ -117,17 +109,15 @@ protected async Task UpdateWebhooksFromFile(string path, string asUser = "", Reporter.WriteError("Couldn't update webhook..."); Reporter.WriteError(e.Message); } - Reporter.WriteSuccess("Updated a webhook:"); if (updatedWebhook != null) { - this.PrintWebhook(updatedWebhook); + this.PrintWebhook(updatedWebhook, json); if (save || !string.IsNullOrEmpty(overrideSavePath) || base._settings.GetAutoSaveSetting()) { saveUpdated.Add(updatedWebhook); } } } - Reporter.WriteInformation("Finished processing webhooks..."); if (save || !string.IsNullOrEmpty(overrideSavePath) || base._settings.GetAutoSaveSetting()) { var fileFormat = base._settings.GetBoxReportsFileFormatSetting(); @@ -146,11 +136,23 @@ protected async Task UpdateWebhooksFromFile(string path, string asUser = "", } catch (Exception e) { - System.Console.WriteLine(e.Message); Reporter.WriteError(e.Message); } } + protected void PrintWebhook(BoxWebhook wh, bool json = false) + { + if (json) + { + base.OutputJson(wh); + return; + } + else + { + this.PrintWebhook(wh); + } + } + protected void PrintWebhook(BoxWebhook wh) { Reporter.WriteInformation($"ID: {wh.Id}"); diff --git a/BoxCLI/Commands/WebhooksSubComands/WebhooksUpdateCommand.cs b/BoxCLI/Commands/WebhooksSubComands/WebhooksUpdateCommand.cs index 9d8885b0..cd04509b 100644 --- a/BoxCLI/Commands/WebhooksSubComands/WebhooksUpdateCommand.cs +++ b/BoxCLI/Commands/WebhooksSubComands/WebhooksUpdateCommand.cs @@ -54,7 +54,12 @@ private async Task RunUpdate() { if (!string.IsNullOrEmpty(_path.Value())) { - await base.UpdateWebhooksFromFile(_path.Value(), _asUser.Value(), this._save.HasValue()); + var json = false; + if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) + { + json = true; + } + await base.UpdateWebhooksFromFile(_path.Value(), _asUser.Value(), this._save.HasValue(), json: json); return; } base.CheckForValue(this._id.Value, this._app, "A webhook ID is required for this call.");