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

Usage warning #66

Merged
merged 4 commits into from
Oct 21, 2017
Merged

Usage warning #66

merged 4 commits into from
Oct 21, 2017

Conversation

veelenga
Copy link
Member

@veelenga veelenga commented Oct 18, 2017

This change is about to warn user regarding usage issues in Readme and while running icr.

Short demo:

$ cat ~/.icr
cat: ~/.icr: No such file or directory

$ icr
WARNING: ICR is not a real REPL and may have side effects.
Please read the documentation carefully and be sure you understand how it works before using it.
Disable this warning with --disable-usage-warning.
icr(0.23.1) > ^D

$ icr
WARNING: ICR is not a real REPL and may have side effects.
Please read the documentation carefully and be sure you understand how it works before using it.
Disable this warning with --disable-usage-warning.
icr(0.23.1) > ^D

$ icr --disable-usage-warning
icr(0.23.1) > ^D

$ icr
icr(0.23.1) > ^D

$ cat ~/.icr
---
print_usage_warning: false

should close #65

/cc @jwoertink @greyblake @RX14 @oprypin @martinos

@RX14
Copy link

RX14 commented Oct 18, 2017

First of all, lets follow the XDG spec on where to place the icr config file. Second of all, it's not immediately obvious to the user that --disable-usage-warning is sticky. You should make ICR exit with no repl and a "Usage warning disabled" message once --disable-usage-warning is passed.

@oprypin
Copy link
Contributor

oprypin commented Oct 18, 2017

If you're gonna add an annoying message AND go through the trouble of adding this setting file, better make it count and ensure that people will actually read it instead of sending them to some vague location.
No references. Include everything from #65 (comment)

Copy link
Member

@greyblake greyblake left a comment

Choose a reason for hiding this comment

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

Cool! Thanks for taking care of it!

require "yaml"

class Icr::Settings
PATH = File.expand_path "~/.icr"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we follow the run commands convention with this filename and make it .icrrc? That would follow other files like .irbrc, .gemrc, .bashrc, .vimrc, etc... We could easily take advantage of having this file for other settings we might want to add.

Copy link
Member

Choose a reason for hiding this comment

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

rc stays for run commands, but this one is actually configuration file..

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right. I was thinking that if this is a flag that gets run when you run icr, and the purpose of the file is to include the flag, it would make sense for it to be a run command. But if we're not going to use it like that, then I guess this is fine.

Copy link

@RX14 RX14 Oct 19, 2017

Choose a reason for hiding this comment

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

Please follow the XDG spec here and use the ${XDG_CONFIG_HOME:-~/.config}/icr/ folder.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I've actually never heard of XDG before. What other utilities can I look at that follow this spec so I can see what they are doing?

Copy link
Contributor

Choose a reason for hiding this comment

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

You'll probably find the spec if you search XDG_CONFIG_HOME. The idea is to read this environment variable (it's almost never set on a typical system) and fall back to $HOME/.config.

@jwoertink
Copy link
Collaborator

I'm not sure how I feel about plastering all over "Not a real REPL"... VS saying something like "Not a full featured REPL".

Really, we should just work out a plan to make it a full repl 😛

Copy link

@RX14 RX14 left a comment

Choose a reason for hiding this comment

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

I think the XDG spec is a must for any modern application creating config files.

@RX14
Copy link

RX14 commented Oct 19, 2017

Honestly if you use the XDG spec, you can simplify this to remove the config file and make it a single 0-byte flag file as you have a whole directory to play with. touch $XDG_CONFIG_HOME/icr/usage-warning-accepted etc.

Copy link
Contributor

@oprypin oprypin left a comment

Choose a reason for hiding this comment

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

I still think this message in its current form is a waste of time. Basically same effect as "RTFM".
It really should be informative to be justified.

@oprypin
Copy link
Contributor

oprypin commented Oct 19, 2017

How about this:


ICR is not a real REPL. It works by building up source code, compiling and re-running all of it after each inputted line. That has side effects, for example:

Current time and random numbers change retroactively.
Files and network sockets are reopened every time.


@veelenga
Copy link
Member Author

veelenga commented Oct 20, 2017

Hey guys. Thanks for review and valuable comments.

@RX14 I know about XDG spec, which was proposed in 2010 and hasn't became a standard (has it?). Moreover, it confuses people on OS X (~/Library or ~/.config?). Windows is a different story. But I like the idea with 0-byte file, which will simplify the things. Also will follow your "second of all" and change the way --disable-usage-warning works :) Thank you!

@oprypin I like your suggestion regarding warning message. Good point, actually 👍

Will prepare changes during weekend, sorry for delay.

@RX14
Copy link

RX14 commented Oct 20, 2017

@veelenga I don't know exactly what you mean by standard but its become very widely used on Linux. About half the applications I use follow the spec, and almost all of the modern ones do. I don't know about how osx handles dot files, but I thought it was the same?

@veelenga
Copy link
Member Author

veelenga commented Oct 20, 2017

I don't know about how osx handles dot files, but I thought it was the same?

Right, same way. But as far as I know XDG suggests to use ~/Library/<App Name> on OS X (which is not actually a "dot" directory). And lot of apps write to ~/.<app-name> and some (modern ones :)) to ~/.config/<app-name>.

So this becomes a mess. Probably this is a lack of configuration on my system, but I expect it to work properly from scratch 😕

@RX14
Copy link

RX14 commented Oct 20, 2017

@veelenga The advice i've seen is for command-line applications to stick to ~/.config and the other linux directories on OSX. Haskell's stdlib does this at least.

Perhaps we should create XDG helpers in the stdlib which handle this platform-specificness for you.

@veelenga
Copy link
Member Author

veelenga commented Oct 20, 2017

@RX14 Does Haskell have it in stdlib? I think you are referring to xdg-basedir package. It works for me just like you said:

$ cabal repl                                                                                                                                                                      
Preprocessing library xdg-basedir-0.2.2...
GHCi, version 8.2.1: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling System.Environment.XDG.BaseDir ( System/Environment/XDG/BaseDir.hs, interpreted )
Ok, 1 module loaded.

*System.Environment.XDG.BaseDir> System.Environment.XDG.BaseDir.getUserConfigDir("icr")
"/Users/_me_/.config/icr"

*System.Environment.XDG.BaseDir> System.Environment.XDG.BaseDir.getUserCacheDir("icr")
"/Users/_me_/.cache/icr"

*System.Environment.XDG.BaseDir> System.Environment.XDG.BaseDir.getAllDataDirs("icr")
["/Users/_me_/.local/share/icr","/usr/local/share/icr","/usr/share/icr"]

Would love to see similar stuff for Crystal 👍

@RX14
Copy link

RX14 commented Oct 20, 2017

Actually this package: doc. But yes, lets just use the simple File.join(ENV["XDG_CONFIG_HOME"]? || "~/.config", "icr") on all platforms for now.

@greyblake
Copy link
Member

greyblake commented Oct 20, 2017 via email

@veelenga
Copy link
Member Author

So now:

$ rm ~/.config/icr/usage_warning_accepted
remove /Users/_me_/.config/icr/usage_warning_accepted? y
$ ./bin/icr
WARNING: ICR is not a full featured REPL.
It works by building up source file, compiling and re-running all of it on each input.
That has side effects:

  * Current time and random numbers change retroactively
  * Files and network/database connections are reopened on every run
  * Running a sleep or benchmark will delay an execution of next inputs
  * Unexpected behavior of fibers, channels, shell commands and maybe others

Be careful while running your commands.

You can disable this warning with --disable-usage-warning flag.
icr(0.23.1) > ^D
$ ./bin/icr
WARNING: ICR is not a full featured REPL.
It works by building up source file, compiling and re-running all of it on each input.
That has side effects:

  * Current time and random numbers change retroactively
  * Files and network/database connections are reopened on every run
  * Running a sleep or benchmark will delay an execution of next inputs
  * Unexpected behavior of fibers, channels, shell commands and maybe others

Be careful while running your commands.

You can disable this warning with --disable-usage-warning flag.
icr(0.23.1) > ^D
$ ./bin/icr --disable-usage-warning
Usage warning disabled. Run ICR again to continue.
$ ./bin/icr
icr(0.23.1) > ^D
$ ls ~/.config/icr/
usage_warning_accepted

@jwoertink
Copy link
Collaborator

I like that message better. Saying "Not a full featured REPL". I noticed I have the .config directory too with some stuff in it already, so it's not far fetched throwing some crystal config stuff in there 😅

I think it looks good.

@veelenga
Copy link
Member Author

veelenga commented Oct 20, 2017

@RX14 @oprypin @greyblake just need your OK or other feedback :)

Copy link
Contributor

@oprypin oprypin left a comment

Choose a reason for hiding this comment

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

You asked for it 😐
mkdir_p is the only absolutely necessary change.
OK otherwise.

src/icr/cli.cr Outdated
def print_usage_warning
puts <<-WARN
WARNING: ICR is not a full featured REPL.
It works by building up source file, compiling and re-running all of it on each input.
Copy link
Contributor

Choose a reason for hiding this comment

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

building up a source file?

src/icr/cli.cr Outdated

* Current time and random numbers change retroactively
* Files and network/database connections are reopened on every run
* Running a sleep or benchmark will delay an execution of next inputs
Copy link
Contributor

Choose a reason for hiding this comment

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

delay an execution?

src/icr/cli.cr Outdated

unless usage_warning_accepted
parser.on("--disable-usage-warning", "Disable usage warning") do
Dir.mkdir CONFIG_HOME unless Dir.exists? CONFIG_HOME
Copy link
Contributor

Choose a reason for hiding this comment

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

mkdir_p and no need to check for existence

src/icr/cli.cr Outdated
@@ -32,7 +54,20 @@ OptionParser.parse! do |parser|
parser.on("-r FILE", "--require=FILE", "auto require FILE") do |filename|
libs.push(%{require "#{filename}"})
end

unless usage_warning_accepted
parser.on("--disable-usage-warning", "Disable usage warning") do
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe don't make the application accept a different set of flags depending on some condition? Swap these two lines. Or even remove unless usage_warning_accepted (see other comment)

src/icr/cli.cr Outdated
usage_warning_accepted = true

puts "Usage warning disabled. Run ICR again to continue."
exit 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Why print this message and why quit? Just let it run as normal. It's more predictable. And, well, it's important for scriptable CLI tools to always have a way to not depend on global state. This is not a scriptable tool but still...

Copy link

Choose a reason for hiding this comment

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

No. We shouldn't make it run as normal because it doesn't make it clear that the warning has been permenantly disabled. Install parallel and follow their "citation" procedure to see how it should be done.

@veelenga veelenga merged commit 960fe90 into master Oct 21, 2017
@veelenga
Copy link
Member Author

Thank you guys for participation and support ;)

@veelenga veelenga deleted the feat/usage-warning branch October 21, 2017 15:17
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.

Consider adding warning to readme
5 participants