<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: tarohida</title>
    <description>The latest articles on DEV Community by tarohida (@tarohida).</description>
    <link>https://dev.to/tarohida</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F356639%2F7f99c2b2-323e-4667-a623-ac32c1da2837.jpeg</url>
      <title>DEV Community: tarohida</title>
      <link>https://dev.to/tarohida</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tarohida"/>
    <language>en</language>
    <item>
      <title>How to define your own custom sub-command to gcloud command</title>
      <dc:creator>tarohida</dc:creator>
      <pubDate>Sun, 14 Apr 2024 02:56:13 +0000</pubDate>
      <link>https://dev.to/tarohida/how-to-define-your-own-custom-sub-command-to-gcloud-command-45pp</link>
      <guid>https://dev.to/tarohida/how-to-define-your-own-custom-sub-command-to-gcloud-command-45pp</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I want to run &lt;code&gt;gcloud compute instances list&lt;/code&gt; command like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I couldn't find how to extend &lt;code&gt;gcloud&lt;/code&gt; command offisialiy, so I extend &lt;code&gt;gcloud&lt;/code&gt; command by to define alias to .bashrc file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Define wrapper and alias
&lt;/h2&gt;

&lt;p&gt;Define below in your .bashrc file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud-wrapper () {
    if [ "$1" = "switch" ]; then
        gcloud config set project "$2"
    elif [ "$1" = "list" ]; then
        if [ "$2" = "instances" ]; then
            gcloud compute instances list
        elif [ "$2" = "ip" ]; then
            gcloud compute instances list --format="table(NAME,EXTERNAL_IP)" --filter="EXTERNAL_IP:*"
        fi
    elif [ "$1" = "start" -o "$1" = "up" ]; then
        gcloud compute instances start $2
    elif [ "$1" = "stop" ]; then
        gcloud comupte instances stop $2
    else
        gcloud "$@"
    fi
}

alias gcloud="gcloud-wrapper"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can extend more to add &lt;code&gt;elif [ "$1" = "list" ]; then&lt;/code&gt; line.&lt;/p&gt;

&lt;p&gt;If sub command not defined, wrapper run original &lt;code&gt;gcloud&lt;/code&gt; command, and you also can use original &lt;code&gt;gcloud&lt;/code&gt; command.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use in dotfiles
&lt;/h2&gt;

&lt;p&gt;Here is my dotfiles.&lt;/p&gt;

&lt;p&gt;You can use solution in your dotfiles.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/tarohida/dotfiles/blob/develop/bashrc.d/96-gcloud.sh"&gt;https://github.com/tarohida/dotfiles/blob/develop/bashrc.d/96-gcloud.sh&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  My Original Article (in Japanese)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://qiita.com/taro-hida/items/97c765cf8bfaf967830a"&gt;https://qiita.com/taro-hida/items/97c765cf8bfaf967830a&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for your reading.&lt;/p&gt;

</description>
      <category>gcloud</category>
      <category>googlecloud</category>
      <category>bashrc</category>
      <category>dotfiles</category>
    </item>
    <item>
      <title> Error on appleboy/ssh-action. dial tcp: lookup example.example on 192.0.2.1:53: i/o timeout</title>
      <dc:creator>tarohida</dc:creator>
      <pubDate>Wed, 19 Jan 2022 04:24:23 +0000</pubDate>
      <link>https://dev.to/tarohida/error-on-appleboyssh-action-dial-tcp-lookup-exampleexample-on-19202153-io-timeout-6ng</link>
      <guid>https://dev.to/tarohida/error-on-appleboyssh-action-dial-tcp-lookup-exampleexample-on-19202153-io-timeout-6ng</guid>
      <description>&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;One day, I get Error like below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2022/01/18 22:51:31 dial tcp: lookup example.example on 192.0.2.1:53: read udp 192.0.2.2:37138-&amp;gt;192.0.2.1:53: i/o timeout
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/appleboy/ssh-action/issues/32"&gt;i/o timeout · Issue #32 · appleboy/ssh-action&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I found this nearly issue. But error in this issue is about &lt;code&gt;22&lt;/code&gt; port. &lt;/p&gt;

&lt;p&gt;My error is about &lt;code&gt;53&lt;/code&gt; port.&lt;/p&gt;

&lt;p&gt;Just be sure, I recreate and replace ssh key. But Problem was not solved.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to solve it
&lt;/h2&gt;

&lt;p&gt;I think it is related to DNS, so I change host address from domain name to IP address.&lt;/p&gt;

&lt;p&gt;And then, pipeline finished successfully.&lt;/p&gt;

&lt;p&gt;I don't know cause, but problem was solved.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      uses: appleboy/ssh-action@master
      with:
        host: ${{ secrets.HOST }}
        username: ${{ secrets.USER }}
        key: ${{ secrets.KEY }}
        port: 22
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Additional Information
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;I replaced actual IP address and domain name to example IP address and domain name.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>githubaction</category>
      <category>appleboysshaction</category>
    </item>
    <item>
      <title>How to fix wrong mapping of namespace in PhpStorm</title>
      <dc:creator>tarohida</dc:creator>
      <pubDate>Wed, 24 Nov 2021 23:48:36 +0000</pubDate>
      <link>https://dev.to/tarohida/how-to-fix-wrong-mapping-of-namespace-in-phpstorm-4ocg</link>
      <guid>https://dev.to/tarohida/how-to-fix-wrong-mapping-of-namespace-in-phpstorm-4ocg</guid>
      <description>&lt;h1&gt;
  
  
  Problems
&lt;/h1&gt;

&lt;p&gt;PhpStorm mapped directories to wrong namespace.&lt;/p&gt;

&lt;p&gt;I updated &lt;code&gt;composer.json&lt;/code&gt;, but it won't work.&lt;/p&gt;

&lt;p&gt;I ran &lt;code&gt;composer install|update|dump-autoload&lt;/code&gt;, but it also won't work.&lt;/p&gt;

&lt;h1&gt;
  
  
  How to solve
&lt;/h1&gt;

&lt;p&gt;I could fix mapping of namespace and directories with this instruction.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.jetbrains.com/help/phpstorm/keeping-namespaces-in-compliance-with-psr0-and-psr4.html#configuring-namespace-roots-manually"&gt;Configure PHP namespaces in a project | PhpStorm&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Environment
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;PhpStorm 2021.1.4&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>phpstorm</category>
    </item>
    <item>
      <title>When I run `exit` command in bash function, how it works.</title>
      <dc:creator>tarohida</dc:creator>
      <pubDate>Fri, 26 Feb 2021 12:40:12 +0000</pubDate>
      <link>https://dev.to/tarohida/when-i-run-exit-command-in-bash-function-how-it-works-384n</link>
      <guid>https://dev.to/tarohida/when-i-run-exit-command-in-bash-function-how-it-works-384n</guid>
      <description>&lt;h2&gt;
  
  
  Environment
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;bash&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Problems
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;I don't know how it works when I exec &lt;code&gt;exit&lt;/code&gt; command in bash function.

&lt;ul&gt;
&lt;li&gt;exit function or exit script?&lt;/li&gt;
&lt;li&gt;What will the exit code look like?&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to solve
&lt;/h2&gt;

&lt;p&gt;I actually did it, and found out below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;script execution ended.&lt;/li&gt;
&lt;li&gt;exit code will be set to exit code specified by &lt;code&gt;exit&lt;/code&gt; command.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Description
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat &amp;lt;&amp;lt; EOF &amp;gt; a.sh
exit_func () {
    exit 0
}

exit_func
echo 'execute here!'
EOF

sh ./a.sh
echo $?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat &amp;lt;&amp;lt; EOF &amp;gt; b.sh
exit_func_254 () {
    exit 254
}

exit_func_254
echo 'execute here!'
EOF

sh ./b.sh
echo $?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;254
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reference
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://linuxize.com/post/bash-functions/"&gt;https://linuxize.com/post/bash-functions/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>When I expand shell variable which have tab chars or space chars, how it works.</title>
      <dc:creator>tarohida</dc:creator>
      <pubDate>Thu, 25 Feb 2021 13:05:38 +0000</pubDate>
      <link>https://dev.to/tarohida/when-i-expand-shell-variable-which-have-tab-chars-or-space-chars-how-it-works-2796</link>
      <guid>https://dev.to/tarohida/when-i-expand-shell-variable-which-have-tab-chars-or-space-chars-how-it-works-2796</guid>
      <description>&lt;h2&gt;
  
  
  Environment
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;bash&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Problems
&lt;/h2&gt;

&lt;p&gt;When I defined shell values such below, how is space chars or tab chars in variable processed?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;packages='
    httpd
    postgresql
    redis
'

yum install ${packages}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to solve
&lt;/h2&gt;

&lt;p&gt;It is expanded to &lt;code&gt;yum httpd postgresql redis&lt;/code&gt;, and it works as expected.&lt;/p&gt;

&lt;h2&gt;
  
  
  Description
&lt;/h2&gt;

&lt;p&gt;Let's see how it is expanded with using &lt;code&gt;echo&lt;/code&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
# your code goes here

packages='
    httpd
    postgresql
    redis
'

echo ${packages}
echo '${packages}'
echo "${packages}"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;httpd postgresql redis
${packages}

    httpd
    postgresql
    redis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://ideone.com/XfbkBI"&gt;https://ideone.com/XfbkBI&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When I quote variable with double quote, it expand, but tab characters or space characters does not replaced with single space.  &lt;/p&gt;

</description>
    </item>
    <item>
      <title>docker-compose `/docker-entrypoint.sh: exec: line 24: require: not found`</title>
      <dc:creator>tarohida</dc:creator>
      <pubDate>Fri, 29 Jan 2021 11:13:16 +0000</pubDate>
      <link>https://dev.to/tarohida/docker-compose-docker-entrypoint-sh-exec-line-24-require-not-found-34cj</link>
      <guid>https://dev.to/tarohida/docker-compose-docker-entrypoint-sh-exec-line-24-require-not-found-34cj</guid>
      <description>&lt;h2&gt;
  
  
  Environment
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Ubuntu 18.04 LTS&lt;/li&gt;
&lt;li&gt;Docker Composer Container&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;run follow command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose run composer require phpunit/phpunit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;got error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/docker-entrypoint.sh: exec: line 24: require: not found
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to solve it.
&lt;/h2&gt;

&lt;p&gt;remove composer.json file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ rm ./composer.json 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and re-run. succeeded.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose run composer require phpunit/phpunit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Description.
&lt;/h2&gt;

&lt;p&gt;when I run &lt;code&gt;--help&lt;/code&gt; command, i got Execption Output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker-compose run composer --help


  [Seld\JsonLint\ParsingException]                                        
  "./composer.json" does not contain valid JSON                           
  Parse error on line 1:                                                  

  ^                                                                       
  Expected one of: 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['  

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;composer.json file is empty.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cat ./composer.json
$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
