Skip to content

Commit 53a503e

Browse files
committed
args: add --gen-config-force + tell the user to put = in optional args
1 parent 9f06def commit 53a503e

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

app/src/main/java/org/toni/customfetch_android/widget/CustomfetchConfigureActivity.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ import android.appwidget.AppWidgetManager
3131
import android.content.Context
3232
import android.content.Intent
3333
import android.os.Bundle
34-
import android.os.Handler
35-
import android.os.Looper
3634
import android.text.Editable
3735
import android.text.SpannableStringBuilder
3836
import android.text.TextPaint
@@ -42,7 +40,6 @@ import android.text.TextWatcher
4240
import android.util.TypedValue
4341
import android.view.View
4442
import android.widget.LinearLayout
45-
import android.widget.Toast
4643
import androidx.core.graphics.toColorInt
4744
import androidx.core.text.toSpanned
4845
import com.skydoves.colorpickerview.listeners.ColorEnvelopeListener
@@ -54,9 +51,6 @@ import org.toni.customfetch_android.getAppSettingsPrefInt
5451
import org.toni.customfetch_android.getAppSettingsPrefString
5552
import org.toni.customfetch_android_lib.mainRender
5653
import org.toni.customfetch_android_lib.mainRenderStr
57-
import java.io.File
58-
import java.nio.file.Files
59-
import kotlin.io.path.Path
6054

6155
/**
6256
* The configuration screen for the [Customfetch] AppWidget.

app/src/main/java/org/toni/customfetch_android_lib/Config.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,21 @@ data class Config(
8282
@SerialName("gui") val gui: GuiConfig = GuiConfig(),
8383
)
8484

85-
fun generateConfig(file: File) {
86-
//if (file.exists())
85+
fun generateConfig(file: File, context: Context?, force: Boolean = false) {
86+
if (file.exists() && !force) {
87+
if (context != null) {
88+
die(context, "Config file already exists. Use --gen-config-force instead for overwriting")
89+
}
90+
return
91+
}
8792
file.writeText(AUTOCONFIG)
8893
}
8994

9095
fun addAliasColor(context: Context, str: String, config: Config) {
9196
val pos = str.indexOf('=')
9297
if (pos == -1)
9398
die(context, "alias color '{}' does NOT have an equal sign '=' for separating config name and value\n" +
94-
"For more check with --help")
99+
"For more check the help section")
95100
val name = str.substring(0, pos)
96101
val value = str.substring(pos + 1)
97102

@@ -103,7 +108,7 @@ fun overrideOption(context: Context, opt: String, config: Config) {
103108
val pos = opt.indexOf('=')
104109
if (pos == -1)
105110
die(context, "override option '{}' does NOT have an equal sign '=' for separating config name and value\n" +
106-
"For more check with --help")
111+
"For more check the help section")
107112
var name = opt.substring(0, pos)
108113
val value = opt.substring(pos + 1)
109114
// usually the user finds inconvenient to write "config.foo"

app/src/main/java/org/toni/customfetch_android_lib/LongFile.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ A command-line, GUI app, android widget system information tool (or neofetch lik
66
77
NOTE: Arguments that takes [<bool>] values, the values can be either: "true", 1, "enable" or leave it empty. Any other value will be treated as false.
88
9-
-n, --no-logo [<bool>] Do not display the logo
10-
-N, --no-color [<bool>] Do not output and parse colors. Useful for stdout or pipe operations
11-
-L, --logo-only [<bool>] Print only the logo
9+
-n, --no-logo=[<bool>] Do not display the logo
10+
-N, --no-color=[<bool>] Do not output and parse colors. Useful for stdout or pipe operations
11+
-L, --logo-only=[<bool>] Print only the logo
1212
-s, --source-path <path> Path to the ascii art or image file to display
1313
-C, --config <path> Path to the config file to use
14-
-a, --ascii-logo-type [<type>]
14+
-a, --ascii-logo-type=[<type>]
1515
The type of ASCII art to apply ("small" or "old").
1616
Basically will add "_<type>" to the logo filename.
1717
It will return the regular linux ascii art if it doesn't exist.
@@ -45,14 +45,14 @@ NOTE: Arguments that takes [<bool>] values, the values can be either: "true", 1,
4545
Not availabile in the android widget app.
4646
4747
--bg-image <path> Path to image to be used in the background in the GUI app (put "disable" for disabling in the config)
48-
--wrap-lines [<bool>] Wrap lines when printing in terminal
48+
--wrap-lines=[<bool>] Wrap lines when printing in terminal
4949
--logo-padding-top <num> Padding of the logo from the top
5050
--logo-padding-left <num> Padding of the logo from the left
5151
--layout-padding-top <num> Padding of the layout from the top
5252
--title-sep <string> A character (or string) to use in ${'$'}<builtin.title_sep>
5353
--sep-reset <string> A character (or string) that when encountered, will automatically reset color
54-
--sep-reset-after [<bool>] Reset color either before or after 'sep-reset'
55-
--gen-config [<path>] Generate default config file to config folder (if path, it will generate to the path)
54+
--sep-reset-after=[<bool>] Reset color either before or after 'sep-reset'
55+
--gen-config=[<path>] Generate default config file to config folder (if path, it will generate to the path)
5656
Will ask for confirmation if file exists already
5757
5858
--color <string> Replace instances of a color with another value.
@@ -481,7 +481,7 @@ fmt = "${'$'}{auto}Disk (%1): ${'$'}<disk(%1)>"
481481
# removable = External disks (USB, SATA, ...)
482482
# read-only = Disks with read-only filesystems
483483
# hidden = Disks that are not really mounted by the user
484-
display-types = ["regular", "removable", "read-only"]
484+
display-types = ["regular", "external", "read-only"]
485485
486486
# In some OSes such as NixOS or Android, there might be some directories that are bind mounted.
487487
# Bind mounted directories create an additional view of an existing directory,

app/src/main/java/org/toni/customfetch_android_lib/Main.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ private fun parseArgs(context: Context, args: Array<String>, config: Config): St
9494
//LongOpt("loop-ms", LongOpt.REQUIRED_ARGUMENT, null, 1009),
9595
//LongOpt("bg-image", LongOpt.REQUIRED_ARGUMENT, null, 1010),
9696
LongOpt("color", LongOpt.REQUIRED_ARGUMENT, null, 1011),
97+
LongOpt("gen-config-force", LongOpt.OPTIONAL_ARGUMENT, null, 1012),
9798

9899
LongOpt(null, 0, null, 0)
99100
)
@@ -125,13 +126,14 @@ private fun parseArgs(context: Context, args: Array<String>, config: Config): St
125126
1000 -> return listLogos(config.t.dataDir)
126127
1001 -> config.t.sepResetAfter = strToBool(handleOptional(g.optarg, "true"))
127128
1002 -> config.t.wrapLines = strToBool(handleOptional(g.optarg, "true"))
128-
1003 -> generateConfig(File(g.optarg))
129+
1003 -> generateConfig(File(g.optarg), context)
129130
1004 -> config.t.sepReset = g.optarg
130131
1005 -> config.t.titleSep = g.optarg
131132
1006 -> config.t.logoPaddingTop = g.optarg.toInt()
132133
1007 -> config.t.logoPaddingLeft = g.optarg.toInt()
133134
1008 -> config.t.layoutPaddingTop = g.optarg.toInt()
134135
1011 -> config.t.aliasColors.add(g.optarg)
136+
1012 -> generateConfig(File(g.optarg), context, true)
135137
}
136138
}
137139
} catch (e: RuntimeException) {
@@ -144,7 +146,7 @@ private fun parseArgs(context: Context, args: Array<String>, config: Config): St
144146
private fun createConfig() {
145147
File(CONFIG_DIR).mkdirs()
146148
if (!File("$CONFIG_DIR/config.toml").exists())
147-
generateConfig(File("$CONFIG_DIR/config.toml"))
149+
generateConfig(File("$CONFIG_DIR/config.toml"), null, true)
148150
}
149151

150152
private fun manageConfigStuff(context: Context, config: Config) {

0 commit comments

Comments
 (0)