Giter VIP home page Giter VIP logo

Comments (9)

lorenzo avatar lorenzo commented on May 13, 2024

There is already a -q and --quiet options. What am I missing?

from app.

beporter avatar beporter commented on May 13, 2024
$ echo 'use Cake\Datasource\ConnectionManager; var_export(ConnectionManager::config("default"));' 
   | bin/cake Console -q
Error: Unknown short option `q`
This shell provides a REPL that you can use to interact with your
application in an interactive fashion. You can use it to run adhoc
queries with your models, or experiment and explore the features of
CakePHP and your application.

You will need to have psysh installed for this Shell to work.

Usage:
cake console [-h]

Options:

--help, -h  Display this help.

from app.

beporter avatar beporter commented on May 13, 2024

TIAS πŸ˜‰

from app.

beporter avatar beporter commented on May 13, 2024

The issue may be that the ConsoleShell doesn't start with its parent OptionParser like the ServerShell does, for example.

ServerShell:

    public function getOptionParser()
    {
        $parser = parent::getOptionParser();

ConsoleShell:

    public function getOptionParser()
    {
        $parser = new ConsoleOptionParser('console', false);

I don't think that will be entirely sufficient though to suppress PsyShell's native output.

from app.

lorenzo avatar lorenzo commented on May 13, 2024

Try changing new ConsoleOptionParser('console', false); to new ConsoleOptionParser('console');

If it works for you, open a PR :D

from app.

beporter avatar beporter commented on May 13, 2024

Yep, that gets closer, but as I suspected, it doesn't fully suppress PsyShell's normal interface output:

$ echo 'use Cake\Datasource\ConnectionManager; var_export(ConnectionManager::config("default")); exit;' | bin/cake Console -q
array (
  'className' => 'Cake\\Database\\Connection',
  'driver' => 'Cake\\Database\\Driver\\Mysql',
  'persistent' => false,
  'host' => 'localhost',
  'username' => 'vagrant',
  'password' => 'vagrant',
  'database' => 'vagrant',
  'encoding' => 'utf8',
  'timezone' => 'UTC',
  'cacheMetadata' => true,
  'quoteIdentifiers' => false,
  'name' => 'default',
)⏎

(Note the funky "return" character at the end, even in spite of using an explicit exit; in my input string.)

from app.

beporter avatar beporter commented on May 13, 2024

So for posterity:

The ⏎ is something PsyShell is adding to var_export() (along with anything else that doesn't explicitly provide a trailing newline). It doesn't get added to print_r() or var_dump(), both of which include a trailing newline already. Unfortunately, that character is also getting added to serialize(), which is the one that would really help here.

To get sane output, there are two choices:

# Strip the visible newline, using sed.
$ echo 'echo serialize([1, 2, 3]); exit;' | bin/cake console -q | sed s/⏎//
a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}

# Include your own newline in the output.
$ echo 'echo serialize([1, 2, 3]) . PHP_EOL; exit;' | bin/cake console -q
a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}

Thanks for the feedback. I think the rest is Psy's problem now.

from app.

beporter avatar beporter commented on May 13, 2024

Created bobthecow/psysh#211.

from app.

ADmad avatar ADmad commented on May 13, 2024

Closing as PR is opened.

from app.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.