Skip to content

Instantly share code, notes, and snippets.

@awendt
Last active March 7, 2018 16:31
Show Gist options
  • Save awendt/a880485e2f3b158f42c8a72eff7e8355 to your computer and use it in GitHub Desktop.
Save awendt/a880485e2f3b158f42c8a72eff7e8355 to your computer and use it in GitHub Desktop.
What configuring a project should feel like

This document is a DRAFT — please leave comments.

A beginner-friendly way of interactively creating config files

Whenever you're trying some new project, you'll likely have to configure something.

This mostly uses one of the following approaches:

  1. Copy the sample config file the project provides, understand the properties and change them
  2. RTFM to find out how to create the config file out of thin air

see this Github search to give you an idea.

What if we had a common way of interactively creating config files?

The pitch

  1. You clone a project
  2. The project contains a file that describes its configuration:
    • format of the config file(s)
    • required keys and values
    • description of the meaning of all keys (possibly including examples)
  3. You run a command, interactively answering questions.
  4. You end up with a valid config you understand.

Let's say the config description is in JSON format:

{
  "config.yml": {
    "format": "yml",
    "entries": {
      "instagram.client_id": {
        "question": "What is the client identifier (client_id) you received when you registered your Instagram app?"
      },
      "instagram.client_secret": {
        "question": "What is the client secret you received when you registered your Instagram app?"
      }
    }
  }
}

When you run, let's say, interview:

Let's create a valid configuration for this project…
Q: What is the client identifier (client_id) you received when you registered your Instagram app?
A: foo
Q: What is the client secret you received when you registered your Instagram app?
A: bar

and you end up with this in config.yml:

instagram:
  client_id: foo
  client_secret: bar

Considerations

  1. Do not allow the target to point out of the project directory (either directly by specifying target to be /etc/passwd or via symlinks)
  2. By default, do not overwrite existing files
  3. Re-running the command might update the configuration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment