@@ -2095,6 +2095,118 @@ describe('usage tests', () => {
20952095 r . logs [ 0 ] . should . include ( 'default: 80 for HTTP and 443 for HTTPS' )
20962096 } )
20972097 } )
2098+
2099+ describe ( 'using positional() without default()' , ( ) => {
2100+ it ( 'should output given desc with default value' , ( ) => {
2101+ const r = checkUsage ( ( ) => yargs ( [ 'url' , '-h' ] )
2102+ . help ( 'h' )
2103+ . command ( 'url' , 'Print a URL' , ( yargs ) => {
2104+ yargs . positional ( 'port' , {
2105+ describe : 'The port value for URL' ,
2106+ defaultDescription : '80 for HTTP and 443 for HTTPS' ,
2107+ default : 80
2108+ } )
2109+ } )
2110+ . wrap ( null )
2111+ . parse ( )
2112+ )
2113+
2114+ r . logs [ 0 ] . should . include ( 'default: 80 for HTTP and 443 for HTTPS' )
2115+ } )
2116+
2117+ it ( 'should output given desc without default value' , ( ) => {
2118+ const r = checkUsage ( ( ) => yargs ( [ 'url' , '-h' ] )
2119+ . help ( 'h' )
2120+ . command ( 'url' , 'Print a URL' , ( yargs ) => {
2121+ yargs . positional ( 'port' , {
2122+ describe : 'The port value for URL' ,
2123+ defaultDescription : '80 for HTTP and 443 for HTTPS'
2124+ } )
2125+ } )
2126+ . wrap ( null )
2127+ . parse ( )
2128+ )
2129+
2130+ r . logs [ 0 ] . should . include ( 'default: 80 for HTTP and 443 for HTTPS' )
2131+ } )
2132+
2133+ it ( 'should prefer given desc over function desc' , ( ) => {
2134+ const r = checkUsage ( ( ) => yargs ( [ 'url' , '-h' ] )
2135+ . help ( 'h' )
2136+ . command ( 'url' , 'Print a URL' , ( yargs ) => {
2137+ yargs . positional ( 'port' , {
2138+ describe : 'The port value for URL' ,
2139+ defaultDescription : '80 for HTTP and 443 for HTTPS' ,
2140+ default : function determinePort ( ) {
2141+ return 80
2142+ }
2143+ } )
2144+ } )
2145+ . wrap ( null )
2146+ . parse ( )
2147+ )
2148+
2149+ r . logs [ 0 ] . should . include ( 'default: 80 for HTTP and 443 for HTTPS' )
2150+ } )
2151+ } )
2152+
2153+ describe ( 'using positional() with default()' , ( ) => {
2154+ it ( 'should prefer default() desc when given last' , ( ) => {
2155+ const r = checkUsage ( ( ) => yargs ( [ 'url' , '-h' ] )
2156+ . help ( 'h' )
2157+ . command ( 'url' , 'Print a URL' , ( yargs ) => {
2158+ yargs
2159+ . positional ( 'port' , {
2160+ describe : 'The port value for URL' ,
2161+ defaultDescription : 'depends on protocol'
2162+ } )
2163+ . default ( 'port' , null , '80 for HTTP and 443 for HTTPS' )
2164+ } )
2165+ . wrap ( null )
2166+ . parse ( )
2167+ )
2168+
2169+ r . logs [ 0 ] . should . include ( 'default: 80 for HTTP and 443 for HTTPS' )
2170+ } )
2171+
2172+ it ( 'should prefer positional() desc when given last' , ( ) => {
2173+ const r = checkUsage ( ( ) => yargs ( [ 'url' , '-h' ] )
2174+ . help ( 'h' )
2175+ . command ( 'url' , 'Print a URL' , ( yargs ) => {
2176+ yargs
2177+ . default ( 'port' , null , '80 for HTTP and 443 for HTTPS' )
2178+ . positional ( 'port' , {
2179+ describe : 'The port value for URL' ,
2180+ defaultDescription : 'depends on protocol'
2181+ } )
2182+ } )
2183+ . wrap ( null )
2184+ . parse ( )
2185+ )
2186+
2187+ r . logs [ 0 ] . should . include ( 'default: depends on protocol' )
2188+ } )
2189+
2190+ it ( 'should prefer positional() desc over default() function' , ( ) => {
2191+ const r = checkUsage ( ( ) => yargs ( [ 'url' , '-h' ] )
2192+ . help ( 'h' )
2193+ . command ( 'url' , 'Print a URL' , ( yargs ) => {
2194+ yargs
2195+ . positional ( 'port' , {
2196+ describe : 'The port value for URL' ,
2197+ defaultDescription : '80 for HTTP and 443 for HTTPS'
2198+ } )
2199+ . default ( 'port' , function determinePort ( ) {
2200+ return 80
2201+ } )
2202+ } )
2203+ . wrap ( null )
2204+ . parse ( )
2205+ )
2206+
2207+ r . logs [ 0 ] . should . include ( 'default: 80 for HTTP and 443 for HTTPS' )
2208+ } )
2209+ } )
20982210 } )
20992211
21002212 describe ( 'normalizeAliases' , ( ) => {
0 commit comments