Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / optionator / lib / help.js
1 // Generated by LiveScript 1.3.1
2 (function(){
3   var ref$, id, find, sort, min, max, map, unlines, nameToRaw, dasherize, wordwrap, getPreText, setHelpStyleDefaults, generateHelpForOption, generateHelp;
4   ref$ = require('prelude-ls'), id = ref$.id, find = ref$.find, sort = ref$.sort, min = ref$.min, max = ref$.max, map = ref$.map, unlines = ref$.unlines;
5   ref$ = require('./util'), nameToRaw = ref$.nameToRaw, dasherize = ref$.dasherize;
6   wordwrap = require('wordwrap');
7   getPreText = function(option, arg$, maxWidth){
8     var mainName, shortNames, ref$, longNames, type, description, aliasSeparator, typeSeparator, initialIndent, names, namesString, namesStringLen, typeSeparatorString, typeSeparatorStringLen, typeString, that, wrap;
9     mainName = option.option, shortNames = (ref$ = option.shortNames) != null
10       ? ref$
11       : [], longNames = (ref$ = option.longNames) != null
12       ? ref$
13       : [], type = option.type, description = option.description;
14     aliasSeparator = arg$.aliasSeparator, typeSeparator = arg$.typeSeparator, initialIndent = arg$.initialIndent;
15     if (option.negateName) {
16       mainName = "no-" + mainName;
17       if (longNames) {
18         longNames = map(function(it){
19           return "no-" + it;
20         }, longNames);
21       }
22     }
23     names = mainName.length === 1
24       ? [mainName].concat(shortNames, longNames)
25       : shortNames.concat([mainName], longNames);
26     namesString = map(nameToRaw, names).join(aliasSeparator);
27     namesStringLen = namesString.length;
28     typeSeparatorString = mainName === 'NUM' ? '::' : typeSeparator;
29     typeSeparatorStringLen = typeSeparatorString.length;
30     typeString = (that = option['enum']) ? "One of: " + that.join(', ') : type;
31     if (maxWidth != null && !option.boolean && initialIndent + namesStringLen + typeSeparatorStringLen + typeString.length > maxWidth) {
32       wrap = wordwrap(initialIndent + namesStringLen + typeSeparatorStringLen, maxWidth);
33       return namesString + "" + typeSeparatorString + wrap(typeString).replace(/^\s+/, '');
34     } else {
35       return namesString + "" + (option.boolean
36         ? ''
37         : typeSeparatorString + "" + typeString);
38     }
39   };
40   setHelpStyleDefaults = function(helpStyle){
41     helpStyle.aliasSeparator == null && (helpStyle.aliasSeparator = ', ');
42     helpStyle.typeSeparator == null && (helpStyle.typeSeparator = ' ');
43     helpStyle.descriptionSeparator == null && (helpStyle.descriptionSeparator = '  ');
44     helpStyle.initialIndent == null && (helpStyle.initialIndent = 2);
45     helpStyle.secondaryIndent == null && (helpStyle.secondaryIndent = 4);
46     helpStyle.maxPadFactor == null && (helpStyle.maxPadFactor = 1.5);
47   };
48   generateHelpForOption = function(getOption, arg$){
49     var stdout, helpStyle, ref$;
50     stdout = arg$.stdout, helpStyle = (ref$ = arg$.helpStyle) != null
51       ? ref$
52       : {};
53     setHelpStyleDefaults(helpStyle);
54     return function(optionName){
55       var maxWidth, wrap, option, e, pre, defaultString, restPositionalString, description, fullDescription, that, preDescription, descriptionString, exampleString, examples, seperator;
56       maxWidth = stdout != null && stdout.isTTY ? stdout.columns - 1 : null;
57       wrap = maxWidth ? wordwrap(maxWidth) : id;
58       try {
59         option = getOption(dasherize(optionName));
60       } catch (e$) {
61         e = e$;
62         return e.message;
63       }
64       pre = getPreText(option, helpStyle);
65       defaultString = option['default'] && !option.negateName ? "\ndefault: " + option['default'] : '';
66       restPositionalString = option.restPositional ? 'Everything after this option is considered a positional argument, even if it looks like an option.' : '';
67       description = option.longDescription || option.description && sentencize(option.description);
68       fullDescription = description && restPositionalString
69         ? description + " " + restPositionalString
70         : (that = description || restPositionalString) ? that : '';
71       preDescription = 'description:';
72       descriptionString = !fullDescription
73         ? ''
74         : maxWidth && fullDescription.length - 1 - preDescription.length > maxWidth
75           ? "\n" + preDescription + "\n" + wrap(fullDescription)
76           : "\n" + preDescription + " " + fullDescription;
77       exampleString = (that = option.example) ? (examples = [].concat(that), examples.length > 1
78         ? "\nexamples:\n" + unlines(examples)
79         : "\nexample: " + examples[0]) : '';
80       seperator = defaultString || descriptionString || exampleString ? "\n" + repeatString$('=', pre.length) : '';
81       return pre + "" + seperator + defaultString + descriptionString + exampleString;
82     };
83   };
84   generateHelp = function(arg$){
85     var options, prepend, append, helpStyle, ref$, stdout, aliasSeparator, typeSeparator, descriptionSeparator, maxPadFactor, initialIndent, secondaryIndent;
86     options = arg$.options, prepend = arg$.prepend, append = arg$.append, helpStyle = (ref$ = arg$.helpStyle) != null
87       ? ref$
88       : {}, stdout = arg$.stdout;
89     setHelpStyleDefaults(helpStyle);
90     aliasSeparator = helpStyle.aliasSeparator, typeSeparator = helpStyle.typeSeparator, descriptionSeparator = helpStyle.descriptionSeparator, maxPadFactor = helpStyle.maxPadFactor, initialIndent = helpStyle.initialIndent, secondaryIndent = helpStyle.secondaryIndent;
91     return function(arg$){
92       var ref$, showHidden, interpolate, maxWidth, output, out, data, optionCount, totalPreLen, preLens, i$, len$, item, that, pre, desc, preLen, sortedPreLens, maxPreLen, preLenMean, x, padAmount, descSepLen, fullWrapCount, partialWrapCount, descLen, totalLen, initialSpace, wrapAllFull, i, wrap;
93       ref$ = arg$ != null
94         ? arg$
95         : {}, showHidden = ref$.showHidden, interpolate = ref$.interpolate;
96       maxWidth = stdout != null && stdout.isTTY ? stdout.columns - 1 : null;
97       output = [];
98       out = function(it){
99         return output.push(it != null ? it : '');
100       };
101       if (prepend) {
102         out(interpolate ? interp(prepend, interpolate) : prepend);
103         out();
104       }
105       data = [];
106       optionCount = 0;
107       totalPreLen = 0;
108       preLens = [];
109       for (i$ = 0, len$ = (ref$ = options).length; i$ < len$; ++i$) {
110         item = ref$[i$];
111         if (showHidden || !item.hidden) {
112           if (that = item.heading) {
113             data.push({
114               type: 'heading',
115               value: that
116             });
117           } else {
118             pre = getPreText(item, helpStyle, maxWidth);
119             desc = item['default'] && !item.negateName
120               ? (that = item.description) != null
121                 ? that + " - default: " + item['default']
122                 : "default: " + item['default']
123               : (that = item.description) != null ? that : '';
124             data.push({
125               type: 'option',
126               pre: pre,
127               desc: desc,
128               descLen: desc.length
129             });
130             preLen = pre.length;
131             optionCount++;
132             totalPreLen += preLen;
133             preLens.push(preLen);
134           }
135         }
136       }
137       sortedPreLens = sort(preLens);
138       maxPreLen = sortedPreLens[sortedPreLens.length - 1];
139       preLenMean = initialIndent + totalPreLen / optionCount;
140       x = optionCount > 2 ? min(preLenMean * maxPadFactor, maxPreLen) : maxPreLen;
141       for (i$ = sortedPreLens.length - 1; i$ >= 0; --i$) {
142         preLen = sortedPreLens[i$];
143         if (preLen <= x) {
144           padAmount = preLen;
145           break;
146         }
147       }
148       descSepLen = descriptionSeparator.length;
149       if (maxWidth != null) {
150         fullWrapCount = 0;
151         partialWrapCount = 0;
152         for (i$ = 0, len$ = data.length; i$ < len$; ++i$) {
153           item = data[i$];
154           if (item.type === 'option') {
155             pre = item.pre, desc = item.desc, descLen = item.descLen;
156             if (descLen === 0) {
157               item.wrap = 'none';
158             } else {
159               preLen = max(padAmount, pre.length) + initialIndent + descSepLen;
160               totalLen = preLen + descLen;
161               if (totalLen > maxWidth) {
162                 if (descLen / 2.5 > maxWidth - preLen) {
163                   fullWrapCount++;
164                   item.wrap = 'full';
165                 } else {
166                   partialWrapCount++;
167                   item.wrap = 'partial';
168                 }
169               } else {
170                 item.wrap = 'none';
171               }
172             }
173           }
174         }
175       }
176       initialSpace = repeatString$(' ', initialIndent);
177       wrapAllFull = optionCount > 1 && fullWrapCount + partialWrapCount * 0.5 > optionCount * 0.5;
178       for (i$ = 0, len$ = data.length; i$ < len$; ++i$) {
179         i = i$;
180         item = data[i$];
181         if (item.type === 'heading') {
182           if (i !== 0) {
183             out();
184           }
185           out(item.value + ":");
186         } else {
187           pre = item.pre, desc = item.desc, descLen = item.descLen, wrap = item.wrap;
188           if (maxWidth != null) {
189             if (wrapAllFull || wrap === 'full') {
190               wrap = wordwrap(initialIndent + secondaryIndent, maxWidth);
191               out(initialSpace + "" + pre + "\n" + wrap(desc));
192               continue;
193             } else if (wrap === 'partial') {
194               wrap = wordwrap(initialIndent + descSepLen + max(padAmount, pre.length), maxWidth);
195               out(initialSpace + "" + pad(pre, padAmount) + descriptionSeparator + wrap(desc).replace(/^\s+/, ''));
196               continue;
197             }
198           }
199           if (descLen === 0) {
200             out(initialSpace + "" + pre);
201           } else {
202             out(initialSpace + "" + pad(pre, padAmount) + descriptionSeparator + desc);
203           }
204         }
205       }
206       if (append) {
207         out();
208         out(interpolate ? interp(append, interpolate) : append);
209       }
210       return unlines(output);
211     };
212   };
213   function pad(str, num){
214     var len, padAmount;
215     len = str.length;
216     padAmount = num - len;
217     return str + "" + repeatString$(' ', padAmount > 0 ? padAmount : 0);
218   }
219   function sentencize(str){
220     var first, rest, period;
221     first = str.charAt(0).toUpperCase();
222     rest = str.slice(1);
223     period = /[\.!\?]$/.test(str) ? '' : '.';
224     return first + "" + rest + period;
225   }
226   function interp(string, object){
227     return string.replace(/{{([a-zA-Z$_][a-zA-Z$_0-9]*)}}/g, function(arg$, key){
228       var ref$;
229       return (ref$ = object[key]) != null
230         ? ref$
231         : "{{" + key + "}}";
232     });
233   }
234   module.exports = {
235     generateHelp: generateHelp,
236     generateHelpForOption: generateHelpForOption
237   };
238   function repeatString$(str, n){
239     for (var r = ''; n > 0; (n >>= 1) && (str += str)) if (n & 1) r += str;
240     return r;
241   }
242 }).call(this);