diff --git a/.gitignore b/.gitignore index 4c49bd7..2392d9a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ .env +.env.* +!.env.dist diff --git a/README.md b/README.md index 1eea07b..56f6580 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ The import file supported is an export file from a [Toggl](https://toggl.com) ap ## Setup +### Basic setup for a single project + 1. Create the `.env` file: ```bash cp .env.dist .env @@ -26,6 +28,25 @@ Env variables prefixed with `TOGGL_` are optional if you use an `--import` optio * `TOGGL_CLIENT_ID`: The client ID in Toggl from whom you want to export your work logs. * `TOGGL_WORKSPACE_ID`: Your workspace ID in Toggl from whom you want to export your work logs. +### Advanced setup for many project + +A very common case is that you want to import your worklogs into different Jira accounts from different Toggle accounts +depending on the project. You can handle it with the `--project` option! We will consider two cases. + +#### CASE 1: One Toggl account and many Jira accounts + +In this case, you most likely work on many Jira projects and want to import all from your one Toggl account where you +log everything. Let's say you work on two projects `sylius` and `symfony`. In your `.env` define common env variables so +all prefixed with `TOGGL_`. In `.env.sylius` and `.env.symfony` specify env variables specific for your Jira account so +prefixed with `ATLASSIAN_`. Now, if you run the command with `--project="symfony"`, files `.env` and `.env.symfony` will +be used. + +#### CASE 2: A different Toggl account and Jira account for each project + +Similar to the case above but you leave `.env` empty. Instead of that file, you define all env vars right in +`.env.`. + + ## Usage Import from Toggl: diff --git a/bin/jira-worklogs-importer b/bin/jira-worklogs-importer index be9bbac..69e9db0 100755 Binary files a/bin/jira-worklogs-importer and b/bin/jira-worklogs-importer differ diff --git a/main.go b/main.go index edf84da..90b39ee 100644 --- a/main.go +++ b/main.go @@ -13,24 +13,34 @@ import ( ) func main() { + var project string var records [][]string var csvFilePathToImport string var since string var until string var dryRun bool - err := godotenv.Load() - if err != nil { - fmt.Println("Error loading .env file.") - return - } - + flag.StringVar(&project, "project", "", "A project name that will load .env. file.") flag.StringVar(&csvFilePathToImport, "import", "", "CSV file path to import.") flag.StringVar(&since, "since", "", "Import work logs since date. Format YYYY-MM-DD.") flag.StringVar(&until, "until", "", "Import work logs until date. Format YYYY-MM-DD.") flag.BoolVar(&dryRun, "dry-run", false, "Dry run. Export work logs but do not import.") flag.Parse() + err := godotenv.Load(".env") + if err != nil { + fmt.Println("Error loading .env file.") + return + } + if project != "" { + projectEnv := fmt.Sprintf(".env.%s", project) + err = godotenv.Load(projectEnv) + if err != nil { + fmt.Printf("Error loading %s file.\n", projectEnv) + return + } + } + optionsValidationFailed := false if since == "" {