address comments from latest code review
This commit is contained in:
parent
cb725eb587
commit
d4dbff084e
@ -154,7 +154,9 @@ do_create.options = [
|
||||
helpArg: 'SIZE',
|
||||
help: 'The size of the volume to create, in the form ' +
|
||||
'`<integer><unit>`, e.g. `20G`. <integer> must be > 0. Supported ' +
|
||||
'units are `G` or `g` for gibibytes and `M` or `m` for mebibytes.',
|
||||
'units are `G` or `g` for gibibytes and `M` or `m` for mebibytes.' +
|
||||
' If <unit> is not provided, <integer> is considered to be in ' +
|
||||
'mebibytes.',
|
||||
completionType: 'tritonvolumesize'
|
||||
},
|
||||
{
|
||||
|
@ -25,8 +25,8 @@ function throwInvalidSize(size) {
|
||||
*
|
||||
* Examples:
|
||||
* - the string '100' represents 100 mebibytes
|
||||
* - the strings '100m' and '100M' represent 100 mebibytes
|
||||
* - the strings '100g' and '100G' represent 100 gibibytes
|
||||
* - the string '100' represents 100 mebibytes
|
||||
*
|
||||
* If "size" is not a valid size string, an error is thrown.
|
||||
*/
|
||||
@ -42,18 +42,22 @@ function parseVolumeSize(size) {
|
||||
M: 1
|
||||
};
|
||||
|
||||
var multiplierSymbol, multiplier;
|
||||
var multiplier = 1; /* default unit is mebibytes */
|
||||
var multiplierSymbol;
|
||||
var baseValue;
|
||||
|
||||
var matches = size.match(/^([1-9]\d*)(g|m|G|M)$/);
|
||||
var matches = size.match(/^([1-9]\d*)(g|m|G|M)?$/);
|
||||
if (!matches) {
|
||||
throwInvalidSize(size);
|
||||
}
|
||||
|
||||
multiplierSymbol = matches[2];
|
||||
if (multiplierSymbol) {
|
||||
multiplier = MULTIPLIERS_TABLE[multiplierSymbol];
|
||||
}
|
||||
|
||||
baseValue = Number(matches[1]);
|
||||
if (isNaN(baseValue) || multiplier === undefined) {
|
||||
if (isNaN(baseValue)) {
|
||||
throwInvalidSize(size);
|
||||
}
|
||||
|
||||
|
@ -63,10 +63,11 @@ test('parseVolumeSize', function (tt) {
|
||||
|
||||
tt.test('parsing valid sizes', function (t) {
|
||||
var validVolumeSizes = [
|
||||
{input: '42g', expectedOutput: 42 * 1024},
|
||||
{input: '42G', expectedOutput: 42 * 1024},
|
||||
{input: '42', expectedOutput: 42},
|
||||
{input: '42m', expectedOutput: 42},
|
||||
{input: '42M', expectedOutput: 42}
|
||||
{input: '42M', expectedOutput: 42},
|
||||
{input: '42g', expectedOutput: 42 * 1024},
|
||||
{input: '42G', expectedOutput: 42 * 1024}
|
||||
];
|
||||
|
||||
validVolumeSizes.forEach(function parse(validVolumeSize) {
|
||||
|
Reference in New Issue
Block a user