Skip to content
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

adds ability to specify user and password via env variables #5980

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions man/nextcloudcmd.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 11 additions & 1 deletion src/cmd/cmd.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/cmd/cmd.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/cmd/cmd.cpp

File src/cmd/cmd.cpp does not conform to Custom style guidelines. (lines 17, 189)
* Copyright (C) by Olivier Goffart <[email protected]>
* Copyright (C) by Klaas Freitag <[email protected]>
* Copyright (C) by Daniel Heule <[email protected]>
Expand All @@ -14,9 +14,10 @@
* for more details.
*/

#include <cstdlib>
#include <iostream>
#include <random>
#include <qcoreapplication.h>

Check failure on line 20 in src/cmd/cmd.cpp

View workflow job for this annotation

GitHub Actions / build

src/cmd/cmd.cpp:20:10 [clang-diagnostic-error]

'qcoreapplication.h' file not found
#include <QStringList>
#include <QUrl>
#include <QFile>
Expand Down Expand Up @@ -185,7 +186,7 @@
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;
Expand Down Expand Up @@ -307,7 +308,7 @@
}
}

int main(int argc, char **argv)

Check warning on line 311 in src/cmd/cmd.cpp

View workflow job for this annotation

GitHub Actions / build

src/cmd/cmd.cpp:311:5 [readability-function-cognitive-complexity]

function 'main' has cognitive complexity of 38 (threshold 25)
{
#ifdef Q_OS_WIN
SetDllDirectory(L"");
Expand Down Expand Up @@ -359,6 +360,7 @@
// 2. From options
// 3. From netrc (if enabled)
// 4. From prompt (if interactive)
// 5. From environment (if non-interactive)

QString user = hostUrl.userName();
QString password = hostUrl.password();
Expand Down Expand Up @@ -390,7 +392,15 @@
if (password.isEmpty()) {
password = queryPassword(user);
}
} 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

Expand Down
Loading