8000 Use JSON.parse for plugins values from cli/env by seth2810 · Pull Request #661 · gemini-testing/gemini · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.

Use JSON.parse for plugins values from cli/env - #661

Merged
seth2810 merged 2 commits into
masterfrom
plugins-parse-env
Nov 7, 2016
Merged

seth2810 merged 2 commits into
masterfrom
plugins-parse-env

Conversation

@seth2810
@seth2810 seth2810 commented Nov 2, 2016
Copy link
Copy Markdown
Contributor

Currently if you set one of values in system.plugins through environment variable using =false, you got string type rather than bool. I propose to use JSON.parse to preprocess values received from environment. Maybe in future be cool to add support for setting values for plugin parameters.

Comment thread lib/config/options.js Outdated
plugins: anyObject(),
plugins: map(option({
parseEnv: JSON.parse,
parseCli: JSON.parse
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

может это в anyObject и унести? Эта функция используется только здесь

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

что там с тестами?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@j0tunn Перенес JSON.parse в anyObject. Добавил тестов.

@seth2810
seth2810 commented Nov 3, 2016
Copy link
Copy Markdown
Contributor Author

/cc @sipayRT @eGavr @DudaGod

@SevInf
SevInf commented Nov 3, 2016 •
Copy link
Copy Markdown
Contributor

Maybe in future be cool to add support for setting values for plugin parameters.

Я предлагал как-то позволить плагинам пробрасывать configparser как-то так:

module.exports = function() {
    // плагин
}

exports.configure = function({ section, map, option }) {
    return section({
        port: option(...)
    })
}

Один из профитов в том числе — перезапись через cli/env из коробки.
Может, обсудим еще раз?

});
});

describe.only('plugins', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only

Comment thread lib/config/util.js
}

return value;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function parsePrimitive(str) {
    try {
        return JSON.parse(str);
    } catch (err) {}
}

А мы не хотим вываливать какой-нибудь warning, если не получилось распарсить?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@j0tunn во всех остальных типах, в случае не валидных значений мы кидаем GeminiError. Не будет ли это создавать лишнюю путаницу?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ну давай тогда и тут бросать

@j0tunn
j0tunn commented Nov 3, 2016
Copy link
Copy Markdown
Contributor

В остальном /ok

@j0tunn
j0tunn commented Nov 3, 2016
Copy link
Copy Markdown
Contributor

Может, обсудим еще раз?

Какой смысл? Можно тупо использовать configparser в плагине - и будет тот же эффект

@SevInf
SevInf commented Nov 3, 2016 •
Copy link
Copy Markdown
Contributor

@j0tunn мы обсуждали это уже. Не будет. Скопипащу из чатика:

чтоб оно так работало, в конфиге должно быть

system:
  plugins:
    optipng:
      geminiOptipngLevel: 1

иначе вот в таком случае

plugin1:
  port: 1234
plugin2:
  port: 3456

--port будет менять оба.

@j0tunn
j0tunn commented Nov 3, 2016
Copy link
Copy Markdown
Contributor

Давай дальше в чатике и пообсуждаем. По идее этот PR твоей идее не мешает

Comment thread lib/config/util.js Outdated
throw new GeminiError('a value must be a primitive type');
}

return value;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

я ж говорю, тебе тут не нужна переменная value вообще просто делай return  JSON.parse(str)

@j0tunn
j0tunn commented Nov 4, 2016
Copy link
Copy Markdown
Contributor

/ok

@seth2810
seth2810 force-pushed the plugins-parse-env branch 2 times, most recently from 0f2e740 to 60cc4f0 Compare November 7, 2016 08:44
@seth2810
seth2810 merged commit bf3048a into master Nov 7, 2016
@tormozz48
tormozz48 deleted the plugins-parse-env branch November 16, 2016 10:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

0