<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!-- NewPage --> <html lang="en"> <head> <!-- Generated by javadoc --> <title>CommandLine.PropertiesDefaultProvider (picocli 4.6.1 API)</title> <link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style"> <script type="text/javascript" src="../script.js"></script> </head> <body> <script type="text/javascript"><!-- try { if (location.href.indexOf('is-external=true') == -1) { parent.document.title="CommandLine.PropertiesDefaultProvider (picocli 4.6.1 API)"; } } catch(err) { } //--> var methods = {"i0":10,"i1":10}; var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]}; var altColor = "altColor"; var rowColor = "rowColor"; var tableTab = "tableTab"; var activeTableTab = "activeTableTab"; </script> <noscript> <div>JavaScript is disabled on your browser.</div> </noscript> <!-- ========= START OF TOP NAVBAR ======= --> <div class="topNav"><a name="navbar.top"> <!-- --> </a> <div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div> <a name="navbar.top.firstrow"> <!-- --> </a> <ul class="navList" title="Navigation"> <li><a href="../overview-summary.html">Overview</a></li> <li><a href="../picocli/package-summary.html">Package</a></li> <li class="navBarCell1Rev">Class</li> <li><a href="package-tree.html">Tree</a></li> <li><a href="../deprecated-list.html">Deprecated</a></li> <li><a href="../index-all.html">Index</a></li> <li><a href="../help-doc.html">Help</a></li> </ul> </div> <div class="subNav"> <ul class="navList"> <li><a href="../picocli/CommandLine.PicocliException.html" title="class in picocli"><span class="typeNameLink">Prev Class</span></a></li> <li><a href="../picocli/CommandLine.Range.html" title="class in picocli"><span class="typeNameLink">Next Class</span></a></li> </ul> <ul class="navList"> <li><a href="../index.html?picocli/CommandLine.PropertiesDefaultProvider.html" target="_top">Frames</a></li> <li><a href="CommandLine.PropertiesDefaultProvider.html" target="_top">No Frames</a></li> </ul> <ul class="navList" id="allclasses_navbar_top"> <li><a href="../allclasses-noframe.html">All Classes</a></li> </ul> <div> <script type="text/javascript"><!-- allClassesLink = document.getElementById("allclasses_navbar_top"); if(window==top) { allClassesLink.style.display = "block"; } else { allClassesLink.style.display = "none"; } //--> </script> </div> <div> <ul class="subNavList"> <li>Summary: </li> <li>Nested | </li> <li>Field | </li> <li><a href="#constructor.summary">Constr</a> | </li> <li><a href="#method.summary">Method</a></li> </ul> <ul class="subNavList"> <li>Detail: </li> <li>Field | </li> <li><a href="#constructor.detail">Constr</a> | </li> <li><a href="#method.detail">Method</a></li> </ul> </div> <a name="skip.navbar.top"> <!-- --> </a></div> <!-- ========= END OF TOP NAVBAR ========= --> <!-- ======== START OF CLASS DATA ======== --> <div class="header"> <div class="subTitle">picocli</div> <h2 title="Class CommandLine.PropertiesDefaultProvider" class="title">Class CommandLine.PropertiesDefaultProvider</h2> </div> <div class="contentContainer"> <ul class="inheritance"> <li><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</a></li> <li> <ul class="inheritance"> <li>picocli.CommandLine.PropertiesDefaultProvider</li> </ul> </li> </ul> <div class="description"> <ul class="blockList"> <li class="blockList"> <dl> <dt>All Implemented Interfaces:</dt> <dd><a href="../picocli/CommandLine.IDefaultValueProvider.html" title="interface in picocli">CommandLine.IDefaultValueProvider</a></dd> </dl> <dl> <dt>Enclosing class:</dt> <dd><a href="../picocli/CommandLine.html" title="class in picocli">CommandLine</a></dd> </dl> <hr> <br> <pre>public static class <span class="typeNameLabel">CommandLine.PropertiesDefaultProvider</span> extends <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a> implements <a href="../picocli/CommandLine.IDefaultValueProvider.html" title="interface in picocli">CommandLine.IDefaultValueProvider</a></pre> <div class="block"><a href="../picocli/CommandLine.IDefaultValueProvider.html" title="interface in picocli"><code>IDefaultValueProvider</code></a> implementation that loads default values for command line options and positional parameters from a properties file or <code>Properties</code> object. <h2>Location</h2> By default, this implementation tries to find a properties file named <code>".<YOURCOMMAND>.properties"</code> in the user home directory, where <code>"<YOURCOMMAND>"</code> is the <a href="../picocli/CommandLine.Command.html#name--">name</a> of the command. If a command has <a href="../picocli/CommandLine.Command.html#aliases--">aliases</a> in addition to its <a href="../picocli/CommandLine.Command.html#name--">name</a>, these aliases are also used to try to find the properties file. For example: <pre> @Command(name = "git", defaultValueProvider = PropertiesDefaultProvider.class) class Git { } </pre> <p>The above will try to load default values from <code>new File(System.getProperty("user.home"), ".git.properties")</code>. </p> <p> The location of the properties file can also be controlled with system property <code>"picocli.defaults.<YOURCOMMAND>.path"</code>, in which case the value of the property must be the path to the file containing the default values. </p> <p> The location of the properties file may also be specified programmatically. For example: </p> <pre> CommandLine cmd = new CommandLine(new MyCommand()); File defaultsFile = new File("path/to/config/mycommand.properties"); cmd.setDefaultValueProvider(new PropertiesDefaultProvider(defaultsFile)); cmd.execute(args); </pre> <h2>Format</h2> <p> For options, the key is either the <a href="../picocli/CommandLine.Option.html#descriptionKey--">descriptionKey</a>, or the option's <a href="../picocli/CommandLine.Model.OptionSpec.html#longestName--">longest name</a>. </p><p> For positional parameters, the key is either the <a href="../picocli/CommandLine.Parameters.html#descriptionKey--">descriptionKey</a>, or the positional parameter's <a href="../picocli/CommandLine.Model.ArgSpec.html#paramLabel--">param label</a>. </p><p> End users may not know what the <code>descriptionKey</code> of your options and positional parameters are, so be sure to document that with your application. </p> <h2>Subcommands</h2> <p> The default values for options and positional parameters of subcommands can be included in the properties file for the top-level command, so that end users need to maintain only a single file. This can be achieved by prefixing the key with the command's qualified name. For example, to give the <code>`git commit`</code> command's <code>--cleanup</code> option a default value of <code>strip</code>, define a key of <code>git.commit.cleanup</code> and assign it a default value. </p><pre> # /home/remko/.git.properties git.commit.cleanup = strip </pre></div> <dl> <dt><span class="simpleTagLabel">Since:</span></dt> <dd>4.1</dd> </dl> </li> </ul> </div> <div class="summary"> <ul class="blockList"> <li class="blockList"> <!-- ======== CONSTRUCTOR SUMMARY ======== --> <ul class="blockList"> <li class="blockList"><a name="constructor.summary"> <!-- --> </a> <h3>Constructor Summary</h3> <table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation"> <caption><span>Constructors</span><span class="tabEnd"> </span></caption> <tr> <th class="colOne" scope="col">Constructor and Description</th> </tr> <tr class="altColor"> <td class="colOne"><code><span class="memberNameLink"><a href="../picocli/CommandLine.PropertiesDefaultProvider.html#PropertiesDefaultProvider--">PropertiesDefaultProvider</a></span>()</code> <div class="block">Default constructor, used when this default value provider is specified in the annotations:</div> </td> </tr> <tr class="rowColor"> <td class="colOne"><code><span class="memberNameLink"><a href="../picocli/CommandLine.PropertiesDefaultProvider.html#PropertiesDefaultProvider-java.io.File-">PropertiesDefaultProvider</a></span>(<a href="https://docs.oracle.com/javase/8/docs/api/java/io/File.html?is-external=true" title="class or interface in java.io">File</a> file)</code> <div class="block">This constructor loads default values from the specified properties file.</div> </td> </tr> <tr class="altColor"> <td class="colOne"><code><span class="memberNameLink"><a href="../picocli/CommandLine.PropertiesDefaultProvider.html#PropertiesDefaultProvider-java.util.Properties-">PropertiesDefaultProvider</a></span>(<a href="https://docs.oracle.com/javase/8/docs/api/java/util/Properties.html?is-external=true" title="class or interface in java.util">Properties</a> properties)</code> <div class="block">This constructor loads default values from the specified properties object.</div> </td> </tr> </table> </li> </ul> <!-- ========== METHOD SUMMARY =========== --> <ul class="blockList"> <li class="blockList"><a name="method.summary"> <!-- --> </a> <h3>Method Summary</h3> <table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation"> <caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd"> </span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd"> </span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd"> </span></span></caption> <tr> <th class="colFirst" scope="col">Modifier and Type</th> <th class="colLast" scope="col">Method and Description</th> </tr> <tr id="i0" class="altColor"> <td class="colFirst"><code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a></code></td> <td class="colLast"><code><span class="memberNameLink"><a href="../picocli/CommandLine.PropertiesDefaultProvider.html#defaultValue-picocli.CommandLine.Model.ArgSpec-">defaultValue</a></span>(<a href="../picocli/CommandLine.Model.ArgSpec.html" title="class in picocli">CommandLine.Model.ArgSpec</a> argSpec)</code> <div class="block">Returns the default value for an option or positional parameter or <code>null</code>.</div> </td> </tr> <tr id="i1" class="rowColor"> <td class="colFirst"><code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a></code></td> <td class="colLast"><code><span class="memberNameLink"><a href="../picocli/CommandLine.PropertiesDefaultProvider.html#toString--">toString</a></span>()</code> </td> </tr> </table> <ul class="blockList"> <li class="blockList"><a name="methods.inherited.from.class.java.lang.Object"> <!-- --> </a> <h3>Methods inherited from class java.lang.<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a></h3> <code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#clone--" title="class or interface in java.lang">clone</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#equals-java.lang.Object-" title="class or interface in java.lang">equals</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#finalize--" title="class or interface in java.lang">finalize</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#getClass--" title="class or interface in java.lang">getClass</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#hashCode--" title="class or interface in java.lang">hashCode</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#notify--" title="class or interface in java.lang">notify</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#notifyAll--" title="class or interface in java.lang">notifyAll</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait--" title="class or interface in java.lang">wait</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait-long-" title="class or interface in java.lang">wait</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait-long-int-" title="class or interface in java.lang">wait</a></code></li> </ul> </li> </ul> </li> </ul> </div> <div class="details"> <ul class="blockList"> <li class="blockList"> <!-- ========= CONSTRUCTOR DETAIL ======== --> <ul class="blockList"> <li class="blockList"><a name="constructor.detail"> <!-- --> </a> <h3>Constructor Detail</h3> <a name="PropertiesDefaultProvider--"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>PropertiesDefaultProvider</h4> <pre>public PropertiesDefaultProvider()</pre> <div class="block">Default constructor, used when this default value provider is specified in the annotations: <pre> @Command(name = "mycmd", defaultValueProvider = PropertiesDefaultProvider.class) class MyCommand // ... </pre> <p> This loads default values from a properties file named <code>".mycmd.properties"</code> in the user home directory. </p><p> The location of the properties file can also be controlled with system property <code>"picocli.defaults.<YOURCOMMAND>.path"</code>, in which case the value of the property must be the path to the file containing the default values. </p></div> <dl> <dt><span class="seeLabel">See Also:</span></dt> <dd><a href="../picocli/CommandLine.PropertiesDefaultProvider.html" title="class in picocli"><code>the PropertiesDefaultProvider class description</code></a></dd> </dl> </li> </ul> <a name="PropertiesDefaultProvider-java.util.Properties-"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>PropertiesDefaultProvider</h4> <pre>public PropertiesDefaultProvider(<a href="https://docs.oracle.com/javase/8/docs/api/java/util/Properties.html?is-external=true" title="class or interface in java.util">Properties</a> properties)</pre> <div class="block">This constructor loads default values from the specified properties object. This may be used programmatically. For example: <pre> CommandLine cmd = new CommandLine(new MyCommand()); Properties defaults = getProperties(); cmd.setDefaultValueProvider(new PropertiesDefaultProvider(defaults)); cmd.execute(args); </pre></div> <dl> <dt><span class="paramLabel">Parameters:</span></dt> <dd><code>properties</code> - the properties containing the default values</dd> <dt><span class="seeLabel">See Also:</span></dt> <dd><a href="../picocli/CommandLine.PropertiesDefaultProvider.html" title="class in picocli"><code>the PropertiesDefaultProvider class description</code></a></dd> </dl> </li> </ul> <a name="PropertiesDefaultProvider-java.io.File-"> <!-- --> </a> <ul class="blockListLast"> <li class="blockList"> <h4>PropertiesDefaultProvider</h4> <pre>public PropertiesDefaultProvider(<a href="https://docs.oracle.com/javase/8/docs/api/java/io/File.html?is-external=true" title="class or interface in java.io">File</a> file)</pre> <div class="block">This constructor loads default values from the specified properties file. This may be used programmatically. For example: <pre> CommandLine cmd = new CommandLine(new MyCommand()); File defaultsFile = new File("path/to/config/file.properties"); cmd.setDefaultValueProvider(new PropertiesDefaultProvider(defaultsFile)); cmd.execute(args); </pre></div> <dl> <dt><span class="paramLabel">Parameters:</span></dt> <dd><code>file</code> - the file to load default values from. Must be non-<code>null</code> and must contain default values in the standard java <a href="https://docs.oracle.com/javase/8/docs/api/java/util/Properties.html?is-external=true" title="class or interface in java.util"><code>Properties</code></a> format.</dd> <dt><span class="seeLabel">See Also:</span></dt> <dd><a href="../picocli/CommandLine.PropertiesDefaultProvider.html" title="class in picocli"><code>the PropertiesDefaultProvider class description</code></a></dd> </dl> </li> </ul> </li> </ul> <!-- ============ METHOD DETAIL ========== --> <ul class="blockList"> <li class="blockList"><a name="method.detail"> <!-- --> </a> <h3>Method Detail</h3> <a name="defaultValue-picocli.CommandLine.Model.ArgSpec-"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>defaultValue</h4> <pre>public <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a> defaultValue(<a href="../picocli/CommandLine.Model.ArgSpec.html" title="class in picocli">CommandLine.Model.ArgSpec</a> argSpec) throws <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Exception.html?is-external=true" title="class or interface in java.lang">Exception</a></pre> <div class="block"><span class="descfrmTypeLabel">Description copied from interface: <code><a href="../picocli/CommandLine.IDefaultValueProvider.html#defaultValue-picocli.CommandLine.Model.ArgSpec-">CommandLine.IDefaultValueProvider</a></code></span></div> <div class="block">Returns the default value for an option or positional parameter or <code>null</code>. The returned value is converted to the type of the option/positional parameter via the same type converter used when populating this option/positional parameter from a command line argument.</div> <dl> <dt><span class="overrideSpecifyLabel">Specified by:</span></dt> <dd><code><a href="../picocli/CommandLine.IDefaultValueProvider.html#defaultValue-picocli.CommandLine.Model.ArgSpec-">defaultValue</a></code> in interface <code><a href="../picocli/CommandLine.IDefaultValueProvider.html" title="interface in picocli">CommandLine.IDefaultValueProvider</a></code></dd> <dt><span class="paramLabel">Parameters:</span></dt> <dd><code>argSpec</code> - the option or positional parameter, never <code>null</code></dd> <dt><span class="returnLabel">Returns:</span></dt> <dd>the default value for the option or positional parameter, or <code>null</code> if this provider has no default value for the specified option or positional parameter</dd> <dt><span class="throwsLabel">Throws:</span></dt> <dd><code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Exception.html?is-external=true" title="class or interface in java.lang">Exception</a></code> - when there was a problem obtaining the default value</dd> </dl> </li> </ul> <a name="toString--"> <!-- --> </a> <ul class="blockListLast"> <li class="blockList"> <h4>toString</h4> <pre>public <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a> toString()</pre> <dl> <dt><span class="overrideSpecifyLabel">Overrides:</span></dt> <dd><code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#toString--" title="class or interface in java.lang">toString</a></code> in class <code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a></code></dd> </dl> </li> </ul> </li> </ul> </li> </ul> </div> </div> <!-- ========= END OF CLASS DATA ========= --> <!-- ======= START OF BOTTOM NAVBAR ====== --> <div class="bottomNav"><a name="navbar.bottom"> <!-- --> </a> <div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div> <a name="navbar.bottom.firstrow"> <!-- --> </a> <ul class="navList" title="Navigation"> <li><a href="../overview-summary.html">Overview</a></li> <li><a href="../picocli/package-summary.html">Package</a></li> <li class="navBarCell1Rev">Class</li> <li><a href="package-tree.html">Tree</a></li> <li><a href="../deprecated-list.html">Deprecated</a></li> <li><a href="../index-all.html">Index</a></li> <li><a href="../help-doc.html">Help</a></li> </ul> </div> <div class="subNav"> <ul class="navList"> <li><a href="../picocli/CommandLine.PicocliException.html" title="class in picocli"><span class="typeNameLink">Prev Class</span></a></li> <li><a href="../picocli/CommandLine.Range.html" title="class in picocli"><span class="typeNameLink">Next Class</span></a></li> </ul> <ul class="navList"> <li><a href="../index.html?picocli/CommandLine.PropertiesDefaultProvider.html" target="_top">Frames</a></li> <li><a href="CommandLine.PropertiesDefaultProvider.html" target="_top">No Frames</a></li> </ul> <ul class="navList" id="allclasses_navbar_bottom"> <li><a href="../allclasses-noframe.html">All Classes</a></li> </ul> <div> <script type="text/javascript"><!-- allClassesLink = document.getElementById("allclasses_navbar_bottom"); if(window==top) { allClassesLink.style.display = "block"; } else { allClassesLink.style.display = "none"; } //--> </script> </div> <div> <ul class="subNavList"> <li>Summary: </li> <li>Nested | </li> <li>Field | </li> <li><a href="#constructor.summary">Constr</a> | </li> <li><a href="#method.summary">Method</a></li> </ul> <ul class="subNavList"> <li>Detail: </li> <li>Field | </li> <li><a href="#constructor.detail">Constr</a> | </li> <li><a href="#method.detail">Method</a></li> </ul> </div> <a name="skip.navbar.bottom"> <!-- --> </a></div> <!-- ======== END OF BOTTOM NAVBAR ======= --> </body> </html>