Repository: rclone/rclone (language: go)

Issue:
`make doc` creates a directory named `$HOME` in the source tree
When I ran `make doc` at f8d782c02de5e42c354f281b4f32c4128fa5db1e, I was surprised to see that it dumped a new directory called `$HOME` in the source tree.

```console
% tree -a '$HOME'
$HOME
└── .config
    └── rclone
```

More specifically, it seems that `make commanddocs` is sufficient to reproduce the bug.

This *probably* has something to do with the Makefile dollar sign business here:

https://github.com/rclone/rclone/blob/f8d782c02de5e42c354f281b4f32c4128fa5db1e/Makefile#L146-L147

I would write up a PR, but I'm not really sure what the intent is. If the goal is to pass the `HOME` environment variable through unmodified, you could just say nothing?
`make doc` creates a directory named `$HOME` in the source tree
When I ran `make doc` at f8d782c02de5e42c354f281b4f32c4128fa5db1e, I was surprised to see that it dumped a new directory called `$HOME` in the source tree.

```console
% tree -a '$HOME'
$HOME
└── .config
    └── rclone
```

More specifically, it seems that `make commanddocs` is sufficient to reproduce the bug.

This *probably* has something to do with the Makefile dollar sign business here:

https://github.com/rclone/rclone/blob/f8d782c02de5e42c354f281b4f32c4128fa5db1e/Makefile#L146-L147

I would write up a PR, but I'm not really sure what the intent is. If the goal is to pass the `HOME` environment variable through unmodified, you could just say nothing?


Discussion / hints:
I think the point is that we want the literal `$HOME` and `$USER` to be present in the generated docs for publishing on rclone.org, not the expanded values from the build system. Maybe this command should run with `--config /notfound` or something to stop it from creating config on disk (https://rclone.org/docs/#config-config-file).
Ah, thanks! I think you're right about this being a hack to so that `$HOME` appears in the docs. Neat trick, I didn't realize `/notfound` was special. It would mean the docs would say `/notfound` instead of `$HOME` though, right?

Another possible solution is to use a placeholder name and then search/replace with sed. I find it a little confusing/terrifying to instruct a Makefile to delete `'$HOME'`, whether single quoted or not, and this way we don't have to.

```diff
 commanddocs: rclone
-       XDG_CACHE_HOME="" XDG_CONFIG_HOME="" HOME="\$$HOME" USER="\$$USER" rclone gendocs docs/content/
+       XDG_CACHE_HOME="" XDG_CONFIG_HOME="" HOME="tmpFakeHomeDirForDocGen" USER="\$$USER" rclone gendocs docs/content/
+       find docs -name '*.md' -exec sed -i tmpFakeHomeDirForDocGen '$HOME' {} \;
+       rmdir -p tmpFakeHomeDirForDocGen/.config/rclone/
```

Alternatively, maybe config.go should be a little more careful about when it creates these directories. Right now, it happens in `makeConfigPath()` which is called by `init()`!  https://github.com/rclone/rclone/blob/f8d782c02de5e42c354f281b4f32c4128fa5db1e/fs/config/config.go#L283
> It would mean the docs would say `/notfound` instead of `$HOME` though, right?

I hope not.. 🙂 My suggestion was just that it should avoid the gendocs command creating the actual config directory (during config init), but that `$HOME` would still be written to docs. Haven't thought it through, so I may be wrong..
> > It would mean the docs would say `/notfound` instead of `$HOME` though, right?
> 
> 
> 
> I hope not.. 🙂 My suggestion was just that it should avoid the gendocs command creating the actual config directory (during config init), but that `$HOME` would still be written to docs. Haven't thought it through, so I may be wrong..

Oops, I think I just got my wires crossed. I see how that would work and it's simpler than my proposed solution.
> I think the point is that we want the literal `$HOME` and `$USER` to be present in the generated docs for publishing on rclone.org, not the expanded values from the build system. Maybe this command should run with `--config /notfound` or something to stop it from creating config on disk (https://rclone.org/docs/#config-config-file).

I think that will work!

The `$HOME` directory is one of those little irritations that has been about for years but I've never got around to investigating!
I think the point is that we want the literal `$HOME` and `$USER` to be present in the generated docs for publishing on rclone.org, not the expanded values from the build system. Maybe this command should run with `--config /notfound` or something to stop it from creating config on disk (https://rclone.org/docs/#config-config-file).
Ah, thanks! I think you're right about this being a hack to so that `$HOME` appears in the docs. Neat trick, I didn't realize `/notfound` was special. It would mean the docs would say `/notfound` instead of `$HOME` though, right?

Another possible solution is to use a placeholder name and then search/replace with sed. I find it a little confusing/terrifying to instruct a Makefile to delete `'$HOME'`, whether single quoted or not, and this way we don't have to.

```diff
 commanddocs: rclone
-       XDG_CACHE_HOME="" XDG_CONFIG_HOME="" HOME="\$$HOME" USER="\$$USER" rclone gendocs docs/content/
+       XDG_CACHE_HOME="" XDG_CONFIG_HOME="" HOME="tmpFakeHomeDirForDocGen" USER="\$$USER" rclone gendocs docs/content/
+       find docs -name '*.md' -exec sed -i tmpFakeHomeDirForDocGen '$HOME' {} \;
+       rmdir -p tmpFakeHomeDirForDocGen/.config/rclone/
```

Alternatively, maybe config.go should be a little more careful about when it creates these directories. Right now, it happens in `makeConfigPath()` which is called by `init()`!  https://github.com/rclone/rclone/blob/f8d782c02de5e42c354f281b4f32c4128fa5db1e/fs/config/config.go#L283
> It would mean the docs would say `/notfound` instead of `$HOME` though, right?

I hope not.. 🙂 My suggestion was just that it should avoid the gendocs command creating the actual config directory (during config init), but that `$HOME` would still be written to docs. Haven't thought it through, so I may be wrong..
> > It would mean the docs would say `/notfound` instead of `$HOME` though, right?
> 
> 
> 
> I hope not.. 🙂 My suggestion was just that it should avoid the gendocs command creating the actual config directory (during config init), but that `$HOME` would still be written to docs. Haven't thought it through, so I may be wrong..

Oops, I think I just got my wires crossed. I see how that would work and it's simpler than my proposed solution.
> I think the point is that we want the literal `$HOME` and `$USER` to be present in the generated docs for publishing on rclone.org, not the expanded values from the build system. Maybe this command should run with `--config /notfound` or something to stop it from creating config on disk (https://rclone.org/docs/#config-config-file).

I think that will work!

The `$HOME` directory is one of those little irritations that has been about for years but I've never got around to investigating!

Fix patch:
diff --git a/Makefile b/Makefile
index 4a9d2240f210a..2e55c5a0cedb7 100644
--- a/Makefile
+++ b/Makefile
@@ -144,10 +144,14 @@ MANUAL.txt:	MANUAL.md
 	pandoc -s --from markdown-smart --to plain MANUAL.md -o MANUAL.txt
 
 commanddocs: rclone
-	XDG_CACHE_HOME="" XDG_CONFIG_HOME="" HOME="\$$HOME" USER="\$$USER" rclone gendocs docs/content/
+	-@rmdir -p '$$HOME/.config/rclone'
+	XDG_CACHE_HOME="" XDG_CONFIG_HOME="" HOME="\$$HOME" USER="\$$USER" rclone gendocs --config=/notfound docs/content/
+	@[ ! -e '$$HOME' ] || (echo 'Error: created unwanted directory named $$HOME' && exit 1)
 
 backenddocs: rclone bin/make_backend_docs.py
+	-@rmdir -p '$$HOME/.config/rclone'
 	XDG_CACHE_HOME="" XDG_CONFIG_HOME="" HOME="\$$HOME" USER="\$$USER" ./bin/make_backend_docs.py
+	@[ ! -e '$$HOME' ] || (echo 'Error: created unwanted directory named $$HOME' && exit 1)
 
 rcdocs: rclone
 	bin/make_rc_docs.sh
diff --git a/bin/make_backend_docs.py b/bin/make_backend_docs.py
index 07da64463e220..c600469c0600c 100755
--- a/bin/make_backend_docs.py
+++ b/bin/make_backend_docs.py
@@ -21,12 +21,12 @@ def find_backends():
 def output_docs(backend, out, cwd):
     """Output documentation for backend options to out"""
     out.flush()
-    subprocess.check_call(["./rclone", "help", "backend", backend], stdout=out)
+    subprocess.check_call(["./rclone", "--config=/notfound", "help", "backend", backend], stdout=out)
 
 def output_backend_tool_docs(backend, out, cwd):
     """Output documentation for backend tool to out"""
     out.flush()
-    subprocess.call(["./rclone", "backend", "help", backend], stdout=out, stderr=subprocess.DEVNULL)
+    subprocess.call(["./rclone", "--config=/notfound", "backend", "help", backend], stdout=out, stderr=subprocess.DEVNULL)
     
 def alter_doc(backend):
     """Alter the documentation for backend"""


Test patch: