-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configuration files #90
Comments
You could likely do sth like:
export LOG_LEVEL=4
source config.env.sh or no? |
TL;DR; We have a fork over at OpenCoarrays, where we specify arguments and their defaults in a separate file. This makes it very human readable, and I don't think it would be too hard to extend our logic for your use case. We are a number of commits behind upstream (b3bp) though, so other functionality may be missing... In general, you can just alter the script to read the arguments and their defaults from a file rather than writing them to the usage variable in the main script. Here is an example of what I am talking about:
|
@kvz that's for environment variables, how you would use that approach for default parameter values? By the way thank you for the B3BP @zbeekman Thank you for the detailed response! I think specifying arguements in a different file for the sake of modularity is brilliant but I'm not sure about doing that for the sake of having default arguements for different environments because now we need to worry about how we're going to version the script arguements. It seems that the direction you're going towards with B3BP is breaking it down into pieces (eventually forming a framework) from what I understand. I've seen similar frameworks lying around that come with a lot of useful modules, really the only reason I'm using B3BP is that everything is one file, which is great for little scripts that do specific tasks that aren't meant to be reusable (or simply aren't worth the time spent to make them reusable) |
In your ideal world, how would you want to specify the defaults for your
use case?
…On Thu, Jul 6, 2017 at 11:18 PM QwertyZW ***@***.***> wrote:
@kvz <https://github.com/kvz> that's for environment variables, how you
would use that approach for default parameter values? By the way thank you
for the B3BP
@zbeekman <https://github.com/zbeekman> Thank you for the detailed
response! I think specifying arguements in a different file for the sake of
modularity is brilliant but I'm not sure about doing that for the sake of
having default arguements for different environments because now we need to
worry about how we're going to version the script arguements.
It seems that the direction you're going towards with B3BP is breaking it
down into pieces (eventually forming a framework) from what I understand.
I've seen similar frameworks lying around that come with a lot of useful
modules, really the only reason I'm using B3BP is that everything is one
file, which is great for little scripts that do specific tasks that aren't
meant to be reusable (or simply aren't worth the time spent to make them
reusable)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#90 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAREPJBeVlGl8R6YgyWSwdPVu5xYy3UWks5sLaNrgaJpZM4OHaYU>
.
|
@zbeekman maybe I was unclear when I said default arguments. So let's say we have our It takes 1 switch Those arguments are key to what the script does and this script will accept these arguments no matter where it goes, those arguments are also tied to the version of the script such that for example version n doesn't support Now what the default values of those arguements are are gonna be different on different environments. Every environment will take in its own value of I always invoke In my ideal world I would have Such that every time someone does ./script.sh on env1 --long-opt is automatically assigned env1 if it isn't specified explicitly to be something else |
@QwertyZW I think I'm following you so far... the intent of my last question, is: "In an ideal world, how would you want to specify/control the defaults on each environment? With local environment variables?With some extra script that gets sourced at the beginning of the file?" For example, if you want to pick up the environment variable diff --git a/main.sh b/main.sh
index 6aa8bcb..0672369 100755
--- a/main.sh
+++ b/main.sh
@@ -135,9 +135,9 @@ function help () {
# you can use bash variables to work around this (so use ${HOME} instead)
# shellcheck disable=SC2015
-[[ "${__usage+x}" ]] || read -r -d '' __usage <<-'EOF' || true # exits non-zero when EOF encountered
+[[ "${__usage+x}" ]] || read -r -d '' __usage <<-EOF || true # exits non-zero when EOF encountered
-f --file [arg] Filename to process. Required.
- -t --temp [arg] Location of tempfile. Default="/tmp/bar"
+ -t --temp [arg] Location of tempfile. Default="${my_dir:-/tmp/bar}"
-v Enable verbose mode, print script as it is executed
-d --debug Enables debug mode
-h --help This page
@@ -376,6 +376,7 @@ info "__base: ${__base}"
info "OSTYPE: ${OSTYPE}"
info "arg_f: ${arg_f}"
+info "arg_t: ${arg_t}"
info "arg_d: ${arg_d}"
info "arg_v: ${arg_v}"
info "arg_h: ${arg_h}" If you're sourcing another file, do it above where If you have a way you would like to see this implemented in b3bp please let us know and we can discuss further. EDIT: N.B.: the removal of quotes around |
This is a feature request.
Having the script automatically parse some sort of configuration file (json,xml,yaml,bash) that dictates default values for its arguements would nice.
Why not just use default parameters?
Assume a case where the scripts are written for a multitude of runtimes (say for e.g; servers) and the default parameters are meant to be different for each runtime.
The text was updated successfully, but these errors were encountered: