command-line-interface

Click Command Line Interfaces: Make options required if other optional option is unset

自古美人都是妖i 提交于 2019-12-18 01:12:07
问题 When writing a command-line interface (CLI) with the Python click library, is it possible to define e.g. three options where the second and third one are only required if the first (optional) one was left unset? My use case is a log-in system which allows me to authenticate either via an authentication token (option 1), or, alternatively, via username (option 2) and password (option 3). If the token was given, there is no need to check for username and password being defined or prompting them

PHP Server Name from Command Line

点点圈 提交于 2019-12-17 23:15:17
问题 Is there a way to detect the name of the server running a PHP script from the command line? There are numerous ways to do this for PHP accessed via HTTP. But there does not appear to be a way to do this for CLI. For example: $_SERVER['SERVER_NAME'] is not available from the command line. 回答1: echo php_uname("n"); see http://php.net/manual/en/function.php-uname.php 回答2: <?php echo gethostname(); // may output e.g,: sandie See http://php.net/manual/en/function.gethostname.php gethostname() is a

How to change port number in vue-cli project

ぐ巨炮叔叔 提交于 2019-12-17 22:33:11
问题 How to change Port number in Vue-cli project so that it run's on another port instead of 8080. 回答1: The port for the Vue-cli webpack template is found in your app root's myApp/config/index.js. All you have to do is modify the port value inside the dev block: dev: { proxyTable: {}, env: require('./dev.env'), port: 4545, assetsSubDirectory: 'static', assetsPublicPath: '/', cssSourceMap: false } Now you can access your app with localhost:4545 also if you have .env file better to set it from

Git error on git pull (unable to update local ref)

佐手、 提交于 2019-12-17 21:41:45
问题 I only have branch master and im getting this error every time i try to "git pull": error: Couldn't set refs/remotes/origin/master From /var/lib/git/xxx/project ! a0f80ea..49177a3 master -> origin/master (unable to update local ref) and when i do "git pull origin master" i get: error: Couldn't set ORIG_HEAD fatal: Cannot update the ref 'ORIG_HEAD'. i have been searching but cant find why 回答1: My team and I ran into this error, unable to update local ref , when doing a pull in SourceTree. We

$_SERVER document root in CLI

戏子无情 提交于 2019-12-17 20:04:51
问题 In CLI $_SERVER['DOCUMENT_ROOT'] is not working. How can I fix this? Is there any other option available. I cannot use relative paths, because files are in various directories. 回答1: $_SERVER contains headers which won't be available in the CLI. The web server defines the document root. In the CLI, you aren't using a web server, so there is no document root. You can try to rely on environmental variables, assuming they are set by your shell. For instance, PWD represents the current directory

Golang: run all .go files within current directory through the command line (multi file package)

不问归期 提交于 2019-12-17 17:38:45
问题 I'm a newcomer to Go. I extremely like the language, but I quickly realised that I needed to start dividing my files due to an increase in program size. go run main.go (with main.go having been the file with my main() function) didn't work and I hit a barrier for a while, because I had no clue how to get my program working. Some quick searching lead me to the answer of go run main.go other.go .. where by typing all the files that my package main consists of, I could get the programming

What will give me something like ruby readline with a default value?

。_饼干妹妹 提交于 2019-12-17 12:36:25
问题 If I want to have a prompt on the terminal with a default value already typed in, how can I do that? Ruby's standard Readline.readline() lets me set the history but not fill in a default value (as far as I can tell, at least) I would like something like this: code: input = Readline.readline_with_default('>', 'default_text') console: > default_text| 回答1: What you are asking is possible with Readline . There's a callback where you can get control after the prompt is displayed and insert some

How do I run Rake tasks within a Ruby script?

拜拜、爱过 提交于 2019-12-17 08:33:14
问题 I have a Rakefile with a Rake task that I would normally call from the command line: rake blog:post Title I'd like to write a Ruby script that calls that Rake task multiple times, but the only solution I see is shelling out using `` (backticks) or system . What's the right way to do this? 回答1: from timocracy.com: require 'rake' def capture_stdout s = StringIO.new oldstdout = $stdout $stdout = s yield s.string ensure $stdout = oldstdout end Rake.application.rake_require 'metric_fetcher', ['../

How do I run Rake tasks within a Ruby script?

大城市里の小女人 提交于 2019-12-17 08:32:12
问题 I have a Rakefile with a Rake task that I would normally call from the command line: rake blog:post Title I'd like to write a Ruby script that calls that Rake task multiple times, but the only solution I see is shelling out using `` (backticks) or system . What's the right way to do this? 回答1: from timocracy.com: require 'rake' def capture_stdout s = StringIO.new oldstdout = $stdout $stdout = s yield s.string ensure $stdout = oldstdout end Rake.application.rake_require 'metric_fetcher', ['../

Is there a way to follow redirects with command line cURL?

戏子无情 提交于 2019-12-17 08:00:04
问题 I know that in a php script: curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); will follow redirects. Is there a way to follow redirects with command line cURL? 回答1: Use the location header flag: curl -L <URL> 回答2: I had a similar problem. I am posting my solution here because I believe it might help one of the commenters. For me, the obstacle was that the page required a login and then gave me a new URL through javascript. Here is what I had to do: curl -c cookiejar -g -O -J -L -F "j_username