Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: custom config file path #255

Closed
wants to merge 9 commits into from
Closed

Conversation

pliski
Copy link
Contributor

@pliski pliski commented May 18, 2019

Description

Address #254.
Allow to specify a custom config file path instead of the default one (~/.tldrrc).
This will allow to use different repositories, themes, cache directories with the same tldr instance.

Example

~/.tldrrc

{
    "pagesRepository": "https://github.com/tldr-pages/tldr",
    "repository": "https://tldr-pages.github.io/assets/tldr.zip",
    "cache": "/home/user/tldr/default",
    "themes": {
    // ...
    },
    "theme": "base16"
}

~/.mytldrrc

{
    "pagesRepository": "https://github.com/myname/myrepo",
    "repository": "https://mypages.github.io/assets/tldr.zip",
    "cache": "/home/user/tldr/default",
    "themes": {
    // ...
    },
    "theme": "ocean"
}

Aliases

alias mytldr='tldr --config-file ".mytldrrc"'

Usage

tldr tar

image

mytldr mate

image

Checklist

Please review this checklist before submitting a pull request.

  • Code compiles correctly
  • Created tests, if possible
  • All tests passing (npm run test:all)
  • Extended the README / documentation, if necessary

@agnivade
Copy link
Member

Please keep a single PR related to only one change. Let us just focus on the custom config file path change here. No need to add the custom cache path or do a version bump. Also please remove your test/.tldrrc.

Thanks.

@agnivade
Copy link
Member

Also, let us name the flag as --config.

@pliski
Copy link
Contributor Author

pliski commented May 19, 2019

@agnivade Actually the PR address only the custom config file. The custom cache path was already featured but not documented. Ok for the version bump.

@pliski
Copy link
Contributor Author

pliski commented May 19, 2019

@agnivade ok for --config also.

@pliski
Copy link
Contributor Author

pliski commented May 19, 2019

Also test/.mytldrrc is needed for the functional test.

@agnivade
Copy link
Member

Right. Could you please remove all the cache file related refactoring that you did ? It becomes hard to review multiple things ? Let us just focus to config file related changes here.

This reverts commit b1e9117.
@pliski
Copy link
Contributor Author

pliski commented May 19, 2019

The only refactoring related to custom cache file is in the README, I can strip this off but not sure if this will help you.

I think your struggle is more related with the fact that config.get() was invoked in the constant declaration and not at runtime (not a best practice by the way); so in the aim of making config file a parameter I'd to transform the former constants in variables and enclose their default assignment in a function.

For example...

Before:

const CACHE_FOLDER = path.join(config.get().cache, 'cache');

After:

let cacheFolder = null;

function getCacheFolder() {
  if (!cacheFolder) {
    cacheFolder = path.join(config.get().cache, 'cache');
  }
  return cacheFolder;
}

You can see this in cache.js and in search.js (mmhh ... duplicate code by the way) and is not related with the custom cache path but with the custom config file path.

@pliski pliski closed this May 19, 2019
@pliski pliski reopened this May 19, 2019
@pliski
Copy link
Contributor Author

pliski commented May 21, 2019

Hi @agnivade, sorry for pushing a little... any chance to see this landed anytime soon?

@vladimyr
Copy link
Collaborator

You could go and revert your changes of package.json while you wait 😉
Bumping dependency versions is ok but that's for another PR.

@agnivade
Copy link
Member

Hey @pliski, I will take some time to review this.

@pliski
Copy link
Contributor Author

pliski commented May 21, 2019

@vladimyr or you could fetch the repo and realize that is already done ;-D
check this commit 118aeaf

@vladimyr
Copy link
Collaborator

@vladimyr or you could fetch the repo and realize that is already done ;-D
check this commit 118aeaf

Now let me quote myself:

Bumping dependency versions is ok but that's for another PR.

And there is a lesson for you:
dependency versions !== package version

diff --git a/package.json b/package.json
index e4271cb..c5823fe 100644
--- a/package.json
+++ b/package.json
@@ -47,25 +47,25 @@
     "test:all": "npm run lint && npm test && npm run test:functional"
   },
   "dependencies": {
-    "chalk": "^2.3.0",
-    "commander": "^2.9.0",
-    "fs-extra": "^4.0.2",
-    "glob": "^7.1.2",
-    "lodash": "^4.17.4",
-    "marked": "^0.3.9",
+    "chalk": "^2.4.2",
+    "commander": "^2.20.0",
+    "fs-extra": "^8.0.1",
+    "glob": "^7.1.4",
+    "lodash": "^4.17.11",
+    "marked": "^0.6.2",
     "ms": "^2.0.0",
-    "natural": "^0.6.0",
-    "node-unzip-2": "^0.2.7",
-    "ora": "^2.0.0",
-    "os-homedir": "^1.0.1",
-    "request": "^2.75.0"
+    "natural": "^0.6.3",
+    "node-unzip-2": "^0.2.8",
+    "ora": "^3.4.0",
+    "os-homedir": "^2.0.0",
+    "request": "^2.88.0"
   },
   "devDependencies": {
     "env-test": "^1.0.0",
-    "eslint": "^4.6.1",
-    "husky": "^0.14.3",
+    "eslint": "^5.16.0",
+    "husky": "^2.3.0",
     "mocha": "^4.0.1",
-    "should": "^13.0.1",
-    "sinon": "^4.1.2"
+    "should": "^13.2.3",
+    "sinon": "^7.3.2"
   }
-}
+}
\ No newline at end of file

Also No newline at end of file is a bad thing, you know...

@pliski
Copy link
Contributor Author

pliski commented May 22, 2019

@vladimyr

And there is a lesson for you:

Are you being sarcastic?
If yes ... please stop.

If no, it's ok, I'm always keen on learning something new and improving myself.

So let's talk about code now 😄 .

@pliski
Copy link
Contributor Author

pliski commented May 22, 2019

@vladimyr

dependency versions !== package version

I misreaded your comment, sorry about that.
I'm reverting the dependency upgrades, even if it is really needed as some packages are nearly two years old.
So I'll make a separate PR if @agnivade is ok.

@pliski
Copy link
Contributor Author

pliski commented May 22, 2019

@vladimyr

Also No newline at end of file is a bad thing, you know...

I agree with you but not everyone does, in other projects I'm on the inverse is required.

To constraint this practice you can propose to enforce eol-last rule in .eslintrc.

This was referenced May 22, 2019
@agnivade
Copy link
Member

so in the aim of making config file a parameter I'd to transform the former constants in variables and enclose their default assignment in a function.

Yes, this is the refactoring that I am talking about. Could you revert this, and just keep the --config flag changes in this PR ?

You can see this in cache.js and in search.js (mmhh ... duplicate code by the way) and is not related with the custom cache path but with the custom config file path.

Yes, this is not good. Also you are declaring a module-level variable, but only using it inside the function. Let's do all this later in a separate PR.

@pliski
Copy link
Contributor Author

pliski commented May 24, 2019

Yes, this is the refactoring that I am talking about. Could you revert this, and just keep the --config flag changes in this PR ?

unfortunately this is part of the "--config flag changes", the other changes wont work without.

This is what I meant when I said:

The only refactoring related to custom cache file is in the README,..

@agnivade
Copy link
Member

Ok, maybe I am missing something. I will look at it in details.

@agnivade
Copy link
Member

Sorry for the delay. It's on my list. I will get to it eventually.

@agnivade
Copy link
Member

I understand the issue now. Looking for a way to tackle this. Thanks for your patience @pliski

@agnivade
Copy link
Member

Hi @pliski - I found a simple way to work around the problem by just resetting the config variable once the file path is set. I created a new PR for this - #262.

You can see the change here - https://github.com/tldr-pages/tldr-node-client/pull/262/files#diff-f7bf2b665273dfa66ffa4ad7c0a52bb9R28

I agree that there are still lot of global variables in the code which pollutes the global state and makes code hard to modify. But just for this change, I think this is reasonable enough. We can refactor the code in a separate PR which can be reviewed properly.

If you are fine with this approach, then you can update your PR accordingly and we can get to reviewing and merging it. Thanks.

@agnivade
Copy link
Member

@pliski - Do you have any thoughts on this ?

@agnivade
Copy link
Member

Closing due to inactivity.

@agnivade agnivade closed this Apr 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants