davetron5000 / gli

Make awesome command-line applications the easy way
http://davetron5000.github.io/gli
Apache License 2.0
1.26k stars 102 forks source link

initconfig => error: can't modify frozen String #265

Closed mickael-palma-argus closed 7 years ago

mickael-palma-argus commented 7 years ago

Hi,

I have # frozen_string_literal: true at the beginning of my bin file. When I run bundle exec bin/app initconfig I get this error:

error: can't modify frozen String

I have to use # frozen_string_literal: false to succeed the command.

How I can I make it work with # frozen_string_literal: true.

Thx for your help.

davetron5000 commented 7 years ago

Can you run your app with GLI_DEBUG=true so that it generates a stack trace and we can see where that error is coming from?

GLI_DEBUG=true my_app whatever -foo=bar # for example
mickael-palma commented 7 years ago
imac:etl4api mickael$ GLI_DEBUG=true bundle exec bin/etl4api initconfig
error: can't modify frozen String
bundler: failed to load command: bin/etl4api (bin/etl4api)
RuntimeError: can't modify frozen String
  /Users/mickael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gli-2.16.0/lib/gli/commands/initconfig.rb:41:in `force_encoding'
  /Users/mickael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gli-2.16.0/lib/gli/commands/initconfig.rb:41:in `block in create_config'
  /Users/mickael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gli-2.16.0/lib/gli/commands/initconfig.rb:38:in `map'
  /Users/mickael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gli-2.16.0/lib/gli/commands/initconfig.rb:38:in `create_config'
  /Users/mickael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gli-2.16.0/lib/gli/commands/initconfig.rb:27:in `block in initialize'
  /Users/mickael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gli-2.16.0/lib/gli/command_support.rb:131:in `execute'
  /Users/mickael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gli-2.16.0/lib/gli/app_support.rb:296:in `block in call_command'
  /Users/mickael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gli-2.16.0/lib/gli/app_support.rb:309:in `call_command'
  /Users/mickael/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gli-2.16.0/lib/gli/app_support.rb:83:in `run'
  bin/etl4api:176:in `<top (required)>'

If you wonder line 176 has : exit run(ARGV)

davetron5000 commented 7 years ago

It's this line: https://github.com/davetron5000/gli/blob/gli-2/lib/gli/commands/initconfig.rb#L41

That line might not be needed any longer—I think it was added for support of an old Ruby. If you want to try removing it and making a PR we can see if the current build matrix passes it.