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

ng completion -b >> ~/.bashrc fails if local cli version is different from global cli version #6343

Closed
carlobonamico opened this issue May 16, 2017 · 6 comments · Fixed by #7366
Labels
needs: investigation Requires some digging to determine if action is needed

Comments

@carlobonamico
Copy link

carlobonamico commented May 16, 2017

Bug Report or Feature Request (mark with an x)

- [X ] bug report -> please search issues before submitting
- [ ] feature request

Versions.

Your global Angular CLI version (1.0.1) is greater than your local
version (1.0.0). The local Angular CLI version is used.

To disable this warning use "ng set --global warnings.versionMismatch=false".
    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.0.0
node: 6.10.3
os: linux x64
@angular/common: 4.0.2
@angular/compiler: 4.0.2
@angular/core: 4.0.2
@angular/forms: 4.0.2
@angular/http: 4.0.2
@angular/platform-browser: 4.0.2
@angular/platform-browser-dynamic: 4.0.2
@angular/router: 4.0.2
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.2

Repro steps.

  1. create project with @angular/cli 1.0.0
  2. install @angular/cli 1.0.1 globally ( npm install -g @angular/cli)
  3. cd in the project folder
  4. run as suggested
    ng completion -b >> ~/.bashrc

At this point .bashrc includes the warning message
Your global Angular CLI version (1.0.1) is greater than your local

The log given by the failure.

Opening a new bash shell prints out

bash: /home/bonamico/.bashrc: line 115: syntax error near unexpected token `('
bash: /home/bonamico/.bashrc: line 115: `Your global Angular CLI version (1.0.1) is greater than your local'
`'`


### Desired functionality.
clarify help for ng completion so that the warning do not come up in the .bashrc file


### Mention any other details that might be useful.

@sumitarora sumitarora self-assigned this May 17, 2017
@sumitarora sumitarora added the needs: investigation Requires some digging to determine if action is needed label May 17, 2017
@catull
Copy link
Contributor

catull commented Aug 2, 2017

This is not a bug, and here's why.

Typically, running ng completion -b >> ~/.bashrc / ng completion -z >> ~/.zshrc should NOT be performed inside an ng project folder.

If you use oh-my-zsh or bash-it, and enable ng tool support, the completion for ng is switched on transparently, as soon as the shell is started and gives control back to the user.

You do not need to run this command constantly, unless you develop the completion functionality in angular/cli.

In fact, ng completion should only be callable outside of an ng app folder, for that matter.

@loganmzz
Copy link
Contributor

loganmzz commented Aug 10, 2017

I consider it a bug (if it is supposed to fail) as:

  • messages must be passed as stderr when you are supposed to generate interpretable content
  • no output must be sent on stdout
  • command must ends with an exit code different from 0

From my point on view, it shouldn't cause an error. As different versions can be used, completion may be able to generate content for appropriate case.

For exemple, outside project, the global version will be used (and so default bash completion may apply). But when on a specific project, you must still have capacity to execute . <(ng completion) in order to have correct "local" completion.

@catull
Copy link
Contributor

catull commented Aug 10, 2017

The user who wants to generate NG completion inside of an ng app folder has to face the consequences.
That includes surprises of discontinued options/commands or changed options etc.

PR #7246 corrects the behaviour, whereby the warning on version mismatch is written as a shell comment to stdout.

This almost satisfies your first concern.

The problem is that both console.log('Message') and console.warn ('Message') write to stdout, only console.error('Message') writes to stderror.
Which means, it would have to be an error to warrant writing to stderror.
@hansl @filipesilva @Brocco
The ng CLI core team decides whether console.error is preferable here.

I disagree with your second point.
An older version of the completion is producing correct output for that specific version.
A warning is not an error, the completion shell output is fine.

The third point would be a small change.
@hansl @filipesilva @Brocco
However, the ng CLI core team decide whether this is acceptable.

@loganmzz
Copy link
Contributor

loganmzz commented Aug 10, 2017

I will speak from my personal experience.

For a CLI tool, completion is not a nice-to-have but must-to-have.

Having different versions of CLI isn't an exceptional case to me. You're working on different project and CLI is installed globally (to be able to use new) and locally (automatically done by ng new and I found it nice to be consistent during project development).
As you wish to be keep uptodate for new projects, you don't want to update your project each time angular team provides new releases (for framework, CLI or any other). Otherwise you will spend time to make integration, not development.

completion command is specific and message also in the case, that output must be interpreted. Tools that provide interpretable content assume that they will be piped/redirected. It is a basic in system programming and one of *nix foundation. You can take a look at how grep or ls commands handle their warnings.

Interfaces for machine can't act as those for humans. In Web development, they are some practise to use Content-Type or URL to have specific rendering (application/html VS application/xml or /api/*** VS /view/**). completion command is one case of specific rendering for machine interface.

@catull
Copy link
Contributor

catull commented Aug 11, 2017

@loganmzz
Created a new PR #7366 much more along your line of thinking.

catull added a commit to catull/angular-cli that referenced this issue Aug 12, 2017
… does not produce output

If an ng app was created with an older version of ng CLI, while the global
ng CLI is more recent, one cannot perform ng completion INSIDE that app folder.
This is due to the warning being written to stdout, which if appended to
~/.bashrc causes the shell to fail to process the English text as commands.
The solution is to display the warning to stderr without producing the
completion output.
In good Unix style, a non-zero status code must returned.
This PR fixes angular#6343.

The PR introduces a breaking change:
- the warning is written to stderr -
- no output is produced
- different status code returned
Brocco pushed a commit that referenced this issue Aug 17, 2017
… does not produce output

If an ng app was created with an older version of ng CLI, while the global
ng CLI is more recent, one cannot perform ng completion INSIDE that app folder.
This is due to the warning being written to stdout, which if appended to
~/.bashrc causes the shell to fail to process the English text as commands.
The solution is to display the warning to stderr without producing the
completion output.
In good Unix style, a non-zero status code must returned.
This PR fixes #6343.

The PR introduces a breaking change:
- the warning is written to stderr -
- no output is produced
- different status code returned
Brocco pushed a commit that referenced this issue Aug 17, 2017
… does not produce output

If an ng app was created with an older version of ng CLI, while the global
ng CLI is more recent, one cannot perform ng completion INSIDE that app folder.
This is due to the warning being written to stdout, which if appended to
~/.bashrc causes the shell to fail to process the English text as commands.
The solution is to display the warning to stderr without producing the
completion output.
In good Unix style, a non-zero status code must returned.
This PR fixes #6343.

The PR introduces a breaking change:
- the warning is written to stderr -
- no output is produced
- different status code returned
dond2clouds pushed a commit to d2clouds/speedray-cli that referenced this issue Apr 23, 2018
… does not produce output

If an ng app was created with an older version of ng CLI, while the global
ng CLI is more recent, one cannot perform ng completion INSIDE that app folder.
This is due to the warning being written to stdout, which if appended to
~/.bashrc causes the shell to fail to process the English text as commands.
The solution is to display the warning to stderr without producing the
completion output.
In good Unix style, a non-zero status code must returned.
This PR fixes angular#6343.

The PR introduces a breaking change:
- the warning is written to stderr -
- no output is produced
- different status code returned
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs: investigation Requires some digging to determine if action is needed
Projects
None yet
4 participants