Skip to content

Commit 29bad9b

Browse files
authored
updated about
1 parent 142289a commit 29bad9b

File tree

1 file changed

+86
-1
lines changed

1 file changed

+86
-1
lines changed

src/main/paradox/about.md

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,89 @@ The typesafe config itself is marked as a 'provided' dependency, so to use this
44

55
The core is simply to convert an Array\[String\] to a Config where the arguments are either paths to configuration resources or simple key=value pairs.
66

7-
Left-most arguments take precedence. In this example, we assume 'prod.conf' is a resource on the classpath:
7+
8+
So, consider this application:
9+
10+
```scala
11+
package acme
12+
13+
import args4c.ConfigApp
14+
import com.typesafe.config.Config
15+
import com.typesafe.scalalogging.StrictLogging
16+
17+
object MyMain extends ConfigApp with StrictLogging {
18+
override type Result = String
19+
override def run(config : Config) = {
20+
logger.info("Running MyMain with:\n" + config.getConfig("acme").summary())
21+
22+
val message = "Hello ${config.getString("acme.name")}"
23+
logger.info(message)
24+
25+
// let's return our message, so our main class can actually act as a function from Config => String
26+
message
27+
}
28+
}
29+
```
30+
31+
which also has these resources:
32+
33+
src/main/resources/reference.conf
34+
```
35+
acme.name : "default"
36+
acme.password : ""
37+
```
38+
39+
and
40+
41+
42+
src/main/resources/acme-test.conf
43+
```
44+
acme.name : "testing"
45+
```
46+
47+
Let's also assume there is an '/app/config/prod.conf' file which contains
48+
```
49+
acme.name : "production"
50+
acme.password : "S3creT"
51+
```
52+
53+
When we run the application, we can observe the left-most arguments take presedence.
54+
55+
### No args (e.g. using our reference.conf)
56+
57+
```scala
58+
java -jar myapp.jar
59+
Running MyMain with:
60+
name : default # reference.conf
61+
password : **** obscured **** # reference.conf
62+
```
63+
64+
### Using the acme-test.conf resource file:
65+
```scala
66+
java -jar myapp.jar acme-test.conf
67+
Running MyMain with:
68+
name : testing # acme-test.conf
69+
password : **** obscured **** # reference.conf
70+
```
71+
Note: If you ran it with e.g.
72+
```
73+
java -cp /opt/config:/opt/lib/myapp.jar acme.MyMain fileInOptConfig.conf
74+
```
75+
It would find and use /opt/config/fileInOptConfig.conf
76+
77+
### Specifying an absolute path to prod.conf
78+
```scala
79+
java -jar myapp.jar /app/config/prod.conf
80+
Running MyMain with:
81+
name : production # /app/config/prod.conf
82+
password : **** obscured **** # /app/config/prod.conf
83+
```
84+
85+
### Our prod.conf file, overridden on the command-line
86+
```scala
87+
java -jar myapp.jar acme.name=foo /app/config/prod.conf
88+
Running MyMain with:
89+
name : foo # command-line
90+
password : **** obscured **** # reference.conf
91+
```
92+

0 commit comments

Comments
 (0)