From 77cfc4b19f918ca14d56b192e3320515baf29233 Mon Sep 17 00:00:00 2001 From: bonni Date: Wed, 16 Aug 2023 21:36:18 +0200 Subject: [PATCH 1/7] reads env vars in --non-interactive Signed-off-by: bonni --- src/cmd/cmd.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cmd/cmd.cpp b/src/cmd/cmd.cpp index 3c940ee2e9adc..7d149ce6ebbb9 100644 --- a/src/cmd/cmd.cpp +++ b/src/cmd/cmd.cpp @@ -14,6 +14,7 @@ * for more details. */ +#include #include #include #include @@ -391,6 +392,13 @@ int main(int argc, char **argv) password = queryPassword(user); } } + //else use ENV? + if(user.isEmpty()){ + user = std::getenv("NC_USER"); + } + if(password.isEmpty()){ + password = std::getennv("NC_PASSWORD"); + } // Find the folder and the original owncloud url From 0f5a0ccf3928d5f3e0f3ad855cbc60d1a8d7cac6 Mon Sep 17 00:00:00 2001 From: bonni Date: Fri, 18 Aug 2023 23:39:17 +0200 Subject: [PATCH 2/7] makes control flow more obvious Signed-off-by: bonni --- src/cmd/cmd.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/cmd/cmd.cpp b/src/cmd/cmd.cpp index 7d149ce6ebbb9..0df645cacfe88 100644 --- a/src/cmd/cmd.cpp +++ b/src/cmd/cmd.cpp @@ -391,14 +391,17 @@ int main(int argc, char **argv) if (password.isEmpty()) { password = queryPassword(user); } + }else{ + //else use ENV? + if(user.isEmpty()){ + user = std::getenv("NC_USER"); + } + if(password.isEmpty()){ + password = std::getennv("NC_PASSWORD"); + } + } - //else use ENV? - if(user.isEmpty()){ - user = std::getenv("NC_USER"); - } - if(password.isEmpty()){ - password = std::getennv("NC_PASSWORD"); - } + // Find the folder and the original owncloud url From 91140b483b02544ca74b3398d47ca4cc895192d4 Mon Sep 17 00:00:00 2001 From: bonni Date: Sat, 19 Aug 2023 00:20:11 +0200 Subject: [PATCH 3/7] adds documentation Signed-off-by: bonni --- man/nextcloudcmd.1.rst | 1 + src/cmd/cmd.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/man/nextcloudcmd.1.rst b/man/nextcloudcmd.1.rst index a78a99a2366e1..d673f1668be4f 100644 --- a/man/nextcloudcmd.1.rst +++ b/man/nextcloudcmd.1.rst @@ -43,6 +43,7 @@ OPTIONS ``—non-interactive`` Do not prompt for questions. + Tries to read $NC_USER and $NC_PASSWORD from the environment. ``—silent``, ``—s`` Inhibits verbose log output. diff --git a/src/cmd/cmd.cpp b/src/cmd/cmd.cpp index 0df645cacfe88..66a5d6509ef67 100644 --- a/src/cmd/cmd.cpp +++ b/src/cmd/cmd.cpp @@ -186,7 +186,7 @@ void help() std::cout << " --user, -u [name] Use [name] as the login name" << std::endl; std::cout << " --password, -p [pass] Use [pass] as password" << std::endl; std::cout << " -n Use netrc (5) for login" << std::endl; - std::cout << " --non-interactive Do not block execution with interaction" << std::endl; + std::cout << " --non-interactive Do not block execution with interaction and tries to read $NC_USER and $NC_PASSWORD if not set by other means" << std::endl; std::cout << " --max-sync-retries [n] Retries maximum n times (default to 3)" << std::endl; std::cout << " --uplimit [n] Limit the upload speed of files to n KB/s" << std::endl; std::cout << " --downlimit [n] Limit the download speed of files to n KB/s" << std::endl; @@ -360,6 +360,7 @@ int main(int argc, char **argv) // 2. From options // 3. From netrc (if enabled) // 4. From prompt (if interactive) + // 4. From environment (if non-interactive) QString user = hostUrl.userName(); QString password = hostUrl.password(); From eb6e7daef244bbb6802266d513c58a58f5b754ba Mon Sep 17 00:00:00 2001 From: bonni Date: Sat, 19 Aug 2023 01:51:57 +0200 Subject: [PATCH 4/7] fixes typo Signed-off-by: bonni --- src/cmd/cmd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/cmd.cpp b/src/cmd/cmd.cpp index 66a5d6509ef67..3eb01fb5fce51 100644 --- a/src/cmd/cmd.cpp +++ b/src/cmd/cmd.cpp @@ -398,7 +398,7 @@ int main(int argc, char **argv) user = std::getenv("NC_USER"); } if(password.isEmpty()){ - password = std::getennv("NC_PASSWORD"); + password = std::getenv("NC_PASSWORD"); } } From 7022216a0ca3ed6d45ca6f90f2554abc44987953 Mon Sep 17 00:00:00 2001 From: internet-memme <142409719+internet-memme@users.noreply.github.com> Date: Mon, 21 Aug 2023 10:17:22 +0200 Subject: [PATCH 5/7] Update src/cmd/cmd.cpp Co-authored-by: Claudio Cambra Signed-off-by: internet-memme <142409719+internet-memme@users.noreply.github.com> --- src/cmd/cmd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/cmd.cpp b/src/cmd/cmd.cpp index 3eb01fb5fce51..ac65b778c3aca 100644 --- a/src/cmd/cmd.cpp +++ b/src/cmd/cmd.cpp @@ -360,7 +360,7 @@ int main(int argc, char **argv) // 2. From options // 3. From netrc (if enabled) // 4. From prompt (if interactive) - // 4. From environment (if non-interactive) + // 5. From environment (if non-interactive) QString user = hostUrl.userName(); QString password = hostUrl.password(); From 30867a40bfb09ad85f5d135c3cbbd4c2ebb6115f Mon Sep 17 00:00:00 2001 From: internet-memme <142409719+internet-memme@users.noreply.github.com> Date: Mon, 21 Aug 2023 10:17:44 +0200 Subject: [PATCH 6/7] Update src/cmd/cmd.cpp Co-authored-by: Claudio Cambra Signed-off-by: internet-memme <142409719+internet-memme@users.noreply.github.com> --- src/cmd/cmd.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/cmd/cmd.cpp b/src/cmd/cmd.cpp index ac65b778c3aca..6df7b396a2963 100644 --- a/src/cmd/cmd.cpp +++ b/src/cmd/cmd.cpp @@ -392,17 +392,14 @@ int main(int argc, char **argv) if (password.isEmpty()) { password = queryPassword(user); } - }else{ - //else use ENV? - if(user.isEmpty()){ - user = std::getenv("NC_USER"); - } - if(password.isEmpty()){ - password = std::getenv("NC_PASSWORD"); - } - + } else { + if (user.isEmpty()) { + user = std::getenv("NC_USER"); + } + if (password.isEmpty()) { + password = std::getenv("NC_PASSWORD"); + } } - // Find the folder and the original owncloud url From f42ce09286078fe7b445ed61d3d692e4048fbfa7 Mon Sep 17 00:00:00 2001 From: bonni Date: Wed, 23 Aug 2023 20:53:53 +0200 Subject: [PATCH 7/7] Revert "Merge branch 'cmd-env-vars' of github.com:internet-memme/nc-desktop into cmd-env-vars" This reverts commit e2e3c92bc3fa9a9a4e9b0fec6954f4aec7e418e7, reversing changes made to def7b65d122f93d58d1f41268247d2de8206f27f. --- src/cmd/cmd.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cmd/cmd.cpp b/src/cmd/cmd.cpp index 6df7b396a2963..13365402a2de1 100644 --- a/src/cmd/cmd.cpp +++ b/src/cmd/cmd.cpp @@ -400,6 +400,7 @@ int main(int argc, char **argv) password = std::getenv("NC_PASSWORD"); } } + // Find the folder and the original owncloud url