Giter Club home page Giter Club logo

vdotenv's Introduction

dotenv module for V

Latest version CI

English / Japanese

vdotenv is a module to read environment variables from .env files

module document.

Usage

Add your application configuration to your .env file in the root of your project:

S3_BUCKET=YOURS3BUCKET
DYNAMODB_TABLE=YOURDYNAMODBTABLE

Then in your V app you can do something like

import os

import zztkm.vdotenv

fn main() {
    // loads env vars from a .env file.
    vdotenv.load()

    s3_bucket := os.getenv('S3_BUCKET')
    dynamodb_table := os.getenv('DYNAMODB_TABLE')

    // ...
}

By default, load looks for a file called .env in your current working directory, but you can also specify the file as follows:

vdotenv.load(".env.develop") // load `.env.development`
vdotenv.load(".env", ".env.develop") // load `.env` and `.env.develop`

You can write comments in the env file:

# This is comment
FOO=BAR
API_URL=YOUR_API_URL # This is inline comment

Installation and Import

Using vpm:

Install/Update:

v install zztkm.vdotenv

Import:

import zztkm.vdotenv

Using github (least recommended):

v install --git https://github.com/hungrybluedev/whisker

Import:

import vdotenv

Contributing

Contributing Guide for this repository.

License

MIT License

TDOO

  • cli app
  • README: add tutorial(for dotenv beginner)

Acknowledgement

Author

vdotenv's People

Contributors

ivixvi avatar litenite42 avatar zztkm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vdotenv's Issues

can't install

$ v install zztkm.vdotenv
cannot compile `/home/ubuntu/src/v/cmd/tools/vpm.v`: 
builder error: 'openssl/rand.h' not found

doesn't handle quotes right

This causes problems. It includes the quotes:

.env:

FOO="foo bar"
BAR='bar baz'

When I load it I get the quotes in the value.

Expected behavior, the quotes should not be included.

app wont' run now


$ v run app.v
internal_memory:31:693: warning: use `${f(expr)}` instead of `$f(expr)`
internal_memory:59:1131: warning: use `${f(expr)}` instead of `$f(expr)`
internal_memory:47:933: warning: use `${f(expr)}` instead of `$f(expr)`
/home/ettinger/.vmodules/zztkm/vdotenv/vdotenv.v:64:21: error: cannot copy map: call `move` or `clone` method (or use a reference)
   62 |     fnames := files.keys()
   63 |     for file_ndx in 0 .. fnames.len {
   64 |         variables := files[fnames[file_ndx]]
      |                           ~~~~~~~~~~~~~~~~~~
   65 |         keys := variables.keys()
   66 |         fname := fnames[file_ndx]
/home/ettinger/.vmodules/zztkm/vdotenv/vdotenv.v:132:22: error: cannot copy map: call `move` or `clone` method (or use a reference)
  130 |             contents := read_file(filename)
  131 |             variables := parse_contents(contents)
  132 |             files[filename] = variables
      |                               ~~~~~~~~~
  133 |         }
  134 |     } else {
/home/ettinger/.vmodules/zztkm/vdotenv/vdotenv.v:137:19: error: cannot copy map: call `move` or `clone` method (or use a reference)
  135 |         contents := read_file('.env')
  136 |         variables := parse_contents(contents)
  137 |         files['.env'] = variables
      |                         ~~~~~~~~~
  138 |     }

getting error in v.02

$ v -v       
V 0.2.1 681ff3c
import zztkm.vdotenv
fn main() {
  vdotenv.load()
  println(os.getenv('DB_FILE'))
}

I get the following error.

V panic: array.get: index out of range (i == 1, a.len == 1)
/tmp/v/app.7487424161921400127.tmp.c:7099: at v_panic: Backtrace
/tmp/v/app.7487424161921400127.tmp.c:6618: by array_get
/tmp/v/app.7487424161921400127.tmp.c:15096: by zztkm__vdotenv__parse_lines
/tmp/v/app.7487424161921400127.tmp.c:15065: by zztkm__vdotenv__parse_contents
/tmp/v/app.7487424161921400127.tmp.c:15119: by zztkm__vdotenv__load_env
/tmp/v/app.7487424161921400127.tmp.c:14979: by zztkm__vdotenv__load
/tmp/v/app.7487424161921400127.tmp.c:18484: by main__main
/tmp/v/app.7487424161921400127.tmp.c:18700: by main

現在設定中の環境変数の一覧の書き出し

共通処理

  • envファイルからキーのみの読み込み
  • キーをもとに現在の設定値を確認
  • 表示用のkey=valueの形にフォーマッティング

書き出し対象

  • ターミナルへの書き出し
  • ファイルへの書き出し

検証

  • テストの実装
    • os周りとpubのテストの実装方法に悩んでいる

Create vdotenv for cli

欲しい機能

  • vdotenv の api を cli で使いたい
  • 何らかのプログラム実行時に環境変数を流し込めるようにしたい

more errors after v update

$ v run app.v 
/home/ettinger/.vmodules/zztkm/vdotenv/vdotenv.v:61:17: error: cannot use `string` as `[]byte` in argument 1 to `strings.Builder.write`
   59 |     mut files := parse_files(filenames)
   60 |     mut output_builder := strings.new_builder(100)
   61 |     output_builder.write('{ ')
      |                    ~~~~~~~~~~~
   62 |     fnames := files.keys()
   63 |     for file_ndx in 0 .. fnames.len {
/home/ettinger/.vmodules/zztkm/vdotenv/vdotenv.v:64:21: error: cannot copy map: call `move` or `clone` method (or use a reference)
   62 |     fnames := files.keys()
   63 |     for file_ndx in 0 .. fnames.len {
   64 |         variables := files[fnames[file_ndx]]
      |                           ~~~~~~~~~~~~~~~~~~
   65 |         keys := variables.keys()
   66 |         fname := fnames[file_ndx]
/home/ettinger/.vmodules/zztkm/vdotenv/vdotenv.v:68:19: error: cannot use `string` as `[]byte` in argument 1 to `strings.Builder.write`
   66 |         fname := fnames[file_ndx]
   67 |         if include_names {
   68 |             output_builder.write('/* file: $fname */ ')
      |                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   69 |         }
   70 |         for i in 0 .. keys.len {
/home/ettinger/.vmodules/zztkm/vdotenv/vdotenv.v:72:19: error: cannot use `string` as `[]byte` in argument 1 to `strings.Builder.write`
   70 |         for i in 0 .. keys.len {
   71 |             quoted_var := variables[keys[i]].replace('"', '\\"')
   72 |             output_builder.write('"${keys[i]}" : "$quoted_var"')
      |                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   73 |             if i < keys.len - 1 {
   74 |                 output_builder.write(', ')
/home/ettinger/.vmodules/zztkm/vdotenv/vdotenv.v:74:20: error: cannot use `string` as `[]byte` in argument 1 to `strings.Builder.write`
   72 |             output_builder.write('"${keys[i]}" : "$quoted_var"')
   73 |             if i < keys.len - 1 {
   74 |                 output_builder.write(', ')
      |                                ~~~~~~~~~~~
   75 |             } else {
   76 |                 output_builder.write('')
/home/ettinger/.vmodules/zztkm/vdotenv/vdotenv.v:76:20: error: cannot use `string` as `[]byte` in argument 1 to `strings.Builder.write`
   74 |                 output_builder.write(', ')
   75 |             } else {
   76 |                 output_builder.write('')
      |                                ~~~~~~~~~
   77 |             }
   78 |         }
/home/ettinger/.vmodules/zztkm/vdotenv/vdotenv.v:80:19: error: cannot use `string` as `[]byte` in argument 1 to `strings.Builder.write`
   78 |         }
   79 |         if file_ndx < filenames.len - 1 {
   80 |             output_builder.write(',')
      |                            ~~~~~~~~~~
   81 |         }
   82 |         output_builder.write(' ')
/home/ettinger/.vmodules/zztkm/vdotenv/vdotenv.v:82:18: error: cannot use `string` as `[]byte` in argument 1 to `strings.Builder.write`
   80 |             output_builder.write(',')
   81 |         }
   82 |         output_builder.write(' ')
      |                        ~~~~~~~~~~
   83 |     }
   84 |     output_builder.write('}')
/home/ettinger/.vmodules/zztkm/vdotenv/vdotenv.v:84:17: error: cannot use `string` as `[]byte` in argument 1 to `strings.Builder.write`
   82 |         output_builder.write(' ')
   83 |     }
   84 |     output_builder.write('}')
      |                    ~~~~~~~~~~
   85 |     return output_builder.str()
   86 | }
/home/ettinger/.vmodules/zztkm/vdotenv/vdotenv.v:132:22: error: cannot copy map: call `move` or `clone` method (or use a reference)
  130 |             contents := read_file(filename)
  131 |             variables := parse_contents(contents)
  132 |             files[filename] = variables
      |                               ~~~~~~~~~
  133 |         }
  134 |     } else {
/home/ettinger/.vmodules/zztkm/vdotenv/vdotenv.v:137:19: error: cannot copy map: call `move` or `clone` method (or use a reference)
  135 |         contents := read_file('.env')
  136 |         variables := parse_contents(contents)
  137 |         files['.env'] = variables
      |                         ~~~~~~~~~
  138 |     }
  139 |     return files

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.