-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from box/folders-update-bugs
Fixed bug with folders update and added folders rename command. Also …
- Loading branch information
Showing
7 changed files
with
120 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using BoxCLI.BoxHome; | ||
using BoxCLI.BoxPlatform.Service; | ||
using BoxCLI.CommandUtilities.Globalization; | ||
using Microsoft.Extensions.CommandLineUtils; | ||
using System.Threading.Tasks; | ||
using Box.V2.Models; | ||
|
||
namespace BoxCLI.Commands.FolderSubCommands | ||
{ | ||
class FolderRenameCommand : FolderSubCommandBase | ||
{ | ||
private CommandLineApplication _app; | ||
private IBoxHome _home; | ||
private CommandArgument _folderId; | ||
private CommandArgument _folderName; | ||
private CommandOption _description; | ||
private CommandOption _etag; | ||
|
||
public FolderRenameCommand(IBoxPlatformServiceBuilder boxPlatformBuilder, IBoxHome home, LocalizedStringsResource names) : base(boxPlatformBuilder, home, names) | ||
{ | ||
_home = home; | ||
} | ||
|
||
|
||
public override void Configure(CommandLineApplication command) | ||
{ | ||
_app = command; | ||
command.Description = "Rename a folder."; | ||
_folderId = command.Argument("folderId", | ||
"Id of folder to rename"); | ||
_folderName = command.Argument("fileName", | ||
"New name of file"); | ||
_description = command.Option("--description", "Change the folder description", CommandOptionType.SingleValue); | ||
_etag = command.Option("--etag", "Only rename if etag value matches", CommandOptionType.SingleValue); | ||
command.OnExecute(async () => | ||
{ | ||
return await this.Execute(); | ||
}); | ||
base.Configure(command); | ||
} | ||
|
||
protected async override Task<int> Execute() | ||
{ | ||
await this.RunRename(); | ||
return await base.Execute(); | ||
} | ||
|
||
protected async Task RunRename() | ||
{ | ||
base.CheckForId(this._folderId.Value, this._app); | ||
base.CheckForValue(this._folderName.Value, _app, "A name value is required to rename a folder."); | ||
var boxClient = base.ConfigureBoxClient(base._asUser.Value()); | ||
var folderRenameRequest = new BoxFolderRequest() | ||
{ | ||
Name = this._folderName.Value, | ||
Id = this._folderId.Value | ||
}; | ||
|
||
if(this._description.HasValue()) | ||
{ | ||
folderRenameRequest.Description = this._description.Value(); | ||
} | ||
BoxFolder folder; | ||
if(this._etag.HasValue()) | ||
{ | ||
folder = await boxClient.FoldersManager.UpdateInformationAsync(folderRenameRequest, etag: this._etag.Value()); | ||
} | ||
else | ||
{ | ||
folder = await boxClient.FoldersManager.UpdateInformationAsync(folderRenameRequest); | ||
} | ||
if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) | ||
{ | ||
base.OutputJson(folder); | ||
return; | ||
} | ||
base.PrintFolder(folder); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Changelog | ||
|
||
## 1.0.1 | ||
|
||
- Fixed minor bug preventing --name, --description, and --etag options from working on the `box folders update` command | ||
- Added a `box folders rename` command. | ||
|
||
## 1.0.0 | ||
|
||
- Welcome to the Box CLI! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters