Skip to main content
The DefDrive CLI automatically saves your configuration to a local file, eliminating the need to re-enter credentials on every run.

Configuration File

The CLI stores configuration in a file named .defdrive_credentials in the directory where you run the CLI.

File Location

.
├── cli/
│   └── main.go
└── .defdrive_credentials  ← Created here when you run CLI from project root
Or if you run the CLI from within the cli/ directory:
cli/
├── main.go
└── .defdrive_credentials  ← Created here
The credentials file is created in your current working directory, not in a fixed system location. If you run the CLI from different directories, separate configuration files will be created.

Stored Fields

The .defdrive_credentials file is a JSON file containing three fields:
{
  "url": "https://defdrive.example.com",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "username": "johndoe"
}

Field Descriptions

FieldDescriptionWhen Set
urlThe DefDrive server URLAfter entering URL in step 0
tokenAuthentication token from login/signupAfter successful authentication
usernameYour DefDrive usernameAfter successful authentication

Configuration Lifecycle

Initial Setup (No Config)

When you run the CLI for the first time:
1

URL Entry

The CLI prompts for the DefDrive server URL
Enter the URL where DefDrive is hosted:
|
2

URL Saved

After you press Enter, the URL is immediately saved to .defdrive_credentials:
{
  "url": "https://your-server.com",
  "token": "",
  "username": ""
}
3

Authentication

You proceed to signup or login
4

Complete Config

After successful authentication, the token and username are added:
{
  "url": "https://your-server.com",
  "token": "eyJhbGc...",
  "username": "yourname"
}

Existing Configuration Detected

When the CLI detects an existing .defdrive_credentials file with both URL and token, it displays a confirmation prompt:
Existing configuration found:
URL: https://your-server.com
Username: yourname

Do you want to proceed with this? (yes/no):
|
Type yes:
  • Continues with the existing configuration
  • Skips authentication flow
  • You can immediately use the CLI with stored credentials
Type no:
  • Resets the configuration (clears URL and token)
  • Starts from the beginning
  • Prompts for URL entry again

Partial Configuration

If .defdrive_credentials exists but only contains a URL (no token), the CLI:
  1. Loads the URL
  2. Skips the URL entry step
  3. Proceeds directly to the authentication menu
This happens if you previously entered a URL but didn’t complete authentication.

Configuration Updates

The configuration file is updated at specific points during CLI execution:

URL Entry

saveConfig(url, "", "") is called when you enter the server URL

Signup Success

saveConfig(url, token, username) is called after successful signup

Login Success

saveConfig(url, token, username) is called after successful login

File Permissions

The credentials file is created with permissions 0644:
  • Owner: Read and write
  • Group: Read only
  • Others: Read only
Security ConsiderationThe .defdrive_credentials file contains your authentication token. For better security:
# Restrict permissions to owner only
chmod 600 .defdrive_credentials
Consider adding .defdrive_credentials to your .gitignore if the CLI directory is part of a Git repository.

Manual Configuration Management

View Current Configuration

cat .defdrive_credentials | jq

Edit Configuration Manually

You can manually edit the JSON file:
nano .defdrive_credentials
Or use any text editor. Ensure the JSON is valid:
{
  "url": "https://new-server.com",
  "token": "your-token-here",
  "username": "your-username"
}

Reset Configuration

To start fresh, delete the credentials file:
rm .defdrive_credentials
The next CLI run will prompt for full setup.

Backup Configuration

cp .defdrive_credentials .defdrive_credentials.backup

Multiple Environments

To manage multiple DefDrive instances, run the CLI from different directories:
project/
├── production/
│   └── .defdrive_credentials  ← Production config
└── staging/
    └── .defdrive_credentials  ← Staging config
Run the CLI from each directory to use different configurations.

Configuration Source Code

The configuration logic is implemented in two functions in cli/main.go:
func saveConfig(url, token, username string) {
    config := map[string]string{"url": url, "token": token, "username": username}
    data, _ := json.Marshal(config)
    _ = ioutil.WriteFile(".defdrive_credentials", data, 0644)
}
These functions are called throughout the CLI flow to persist and retrieve configuration.

Next Steps

Authentication

Learn about the signup and login flows

Introduction

Return to the CLI overview

Build docs developers (and LLMs) love