Skip to content

Commit

Permalink
Cleaned up logging, fixed bulk action logging with JSON setting, and …
Browse files Browse the repository at this point in the history
…bumped version to 1.0.0 for release
  • Loading branch information
amgrobelny-box committed Oct 12, 2017
1 parent b8da912 commit 30cc735
Show file tree
Hide file tree
Showing 34 changed files with 248 additions and 148 deletions.
2 changes: 1 addition & 1 deletion BoxCLI/BoxCLIInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
1 change: 0 additions & 1 deletion BoxCLI/BoxHome/BoxHomeFiles/BoxDefaultSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ private string CreateBoxReportsFolder()
}
else
{
System.Console.WriteLine("Found existing box reports folder...");
return path;
}
}
Expand Down
6 changes: 3 additions & 3 deletions BoxCLI/BoxPlatform/Utilities/BoxCollectionsIterators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(Action<T> print, BoxCollectionMarkerBased<T> 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<BoxEnterpriseEvent> print, BoxEventCollection<BoxEnterpriseEvent> 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();
}

Expand Down
2 changes: 0 additions & 2 deletions BoxCLI/CommandUtilities/CsvModels/BoxMetadataMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Dictionary<string, object>>(text);
}

Expand Down
1 change: 0 additions & 1 deletion BoxCLI/CommandUtilities/CsvModels/BoxWebhookMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public sealed class BoxWebhookTargetMap : CsvClassMap<BoxEntity>
{
public BoxWebhookTargetMap()
{
System.Console.WriteLine("Mapping target...");
Map(m => m.Id).Name("TargetId");
Map(m => m.Type).Name("TargetType");
}
Expand Down
25 changes: 13 additions & 12 deletions BoxCLI/Commands/BoxBaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand Down Expand Up @@ -343,14 +356,12 @@ protected virtual bool WriteMetadataTemplateCollectionResultsToReport(List<BoxMe
}
protected virtual bool WriteEventListResultsToReport(List<BoxEnterpriseEvent> 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<List<BoxEnterpriseEvent>>(entity));
return true;
Expand Down Expand Up @@ -388,14 +399,12 @@ protected virtual bool WriteEventListResultsToReport(List<BoxEnterpriseEvent> en
protected virtual bool WriteListResultsToReport<T, M>(List<T> 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<T>();
collection.Entries = new List<T>();
Expand Down Expand Up @@ -436,14 +445,12 @@ protected virtual bool WriteListResultsToReport<T, M>(List<T> entity, string fil
protected virtual bool WriteOffsetCollectionResultsToReport<T, M>(BoxCollection<T> 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<BoxCollection<T>>(entity));
return true;
Expand Down Expand Up @@ -480,14 +487,12 @@ protected virtual bool WriteOffsetCollectionResultsToReport<T, M>(BoxCollection<
protected virtual bool WriteMarkerCollectionResultsToReport<T, M>(BoxCollectionMarkerBased<T> 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<BoxCollectionMarkerBased<T>>(entity));
return true;
Expand Down Expand Up @@ -599,11 +604,9 @@ protected virtual List<BoxBulkDownload> 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<T>().ToList();
}
Expand Down Expand Up @@ -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();
}
Expand Down
35 changes: 28 additions & 7 deletions BoxCLI/Commands/BoxItemCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,38 @@ 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)
{
Reporter.WriteInformation($"File ID: {file.Id}");
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}");
Expand Down Expand Up @@ -124,7 +148,6 @@ protected virtual void PrintTask(BoxTask task)
protected List<T> ReadCustomFile<T, M>(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))
Expand All @@ -135,11 +158,9 @@ protected List<T> ReadCustomFile<T, M>(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<T>().ToList();
}
Expand Down Expand Up @@ -237,7 +258,7 @@ protected async Task<BoxFile> 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
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ private async Task RunList()
BoxCollection<BoxCollaboration> 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
Expand All @@ -78,12 +76,10 @@ private async Task RunList()
BoxCollection<BoxCollaboration> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using BoxCLI.BoxHome;
using BoxCLI.CommandUtilities;
using Microsoft.Extensions.CommandLineUtils;

namespace BoxCLI.Commands.ConfigureSubCommands.ConfigureEnvironmentsSubCommands
Expand All @@ -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}");
}
}
}
1 change: 0 additions & 1 deletion BoxCLI/Commands/EventSubCommands/EventSubCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
7 changes: 6 additions & 1 deletion BoxCLI/Commands/FileSubCommand/FileUploadCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 30cc735

Please sign in to comment.