Skip to content

Commit

Permalink
Add Remove-CouchDBDesignDocumentAttachment cmdlet;
Browse files Browse the repository at this point in the history
Fix Remove-CouchDBAttachment cmdlet:
Add Force parameter;
Other fix.
  • Loading branch information
MatteoGuadrini committed Aug 7, 2019
1 parent dceecd0 commit e6e9545
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 19 deletions.
2 changes: 2 additions & 0 deletions PSCouchDB/PSCouchDB.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
"Remove-CouchDBDatabase",
"Remove-CouchDBDocument",
"Remove-CouchDBDesignDocument",
"Remove-CouchDBDesignDocumentAttachment",
"Remove-CouchDBAttachment",
"Remove-CouchDBUser",
"Remove-CouchDBAdmin",
Expand Down Expand Up @@ -229,6 +230,7 @@
"rcdb",
"rcdoc",
"rcddoc",
"rdatt",
"rcatt",
"rcusr",
"rcadm",
Expand Down
62 changes: 60 additions & 2 deletions PSCouchDB/PSCouchDB.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ New-Alias -Name "ncidx" -Value New-CouchDBIndex -Option ReadOnly
New-Alias -Name "rcdb" -Value Remove-CouchDBDatabase -Option ReadOnly
New-Alias -Name "rcdoc" -Value Remove-CouchDBDocument -Option ReadOnly
New-Alias -Name "rcddoc" -Value Remove-CouchDBDesignDocument -Option ReadOnly
New-Alias -Name "rdatt" -Value Remove-CouchDBDesignDocumentAttachment -Option ReadOnly
New-Alias -Name "rcatt" -Value Remove-CouchDBAttachment -Option ReadOnly
New-Alias -Name "rcusr" -Value Remove-CouchDBUser -Option ReadOnly
New-Alias -Name "rcadm" -Value Remove-CouchDBAdmin -Option ReadOnly
Expand Down Expand Up @@ -3080,7 +3081,7 @@ function Set-CouchDBDocument () {
# Check BatchMode
if ($BatchMode.IsPresent) {
$Document += "?batch=ok"
# Check NoConflict
# Check NoConflict
} elseif ($NoConflict.IsPresent -and $Revision) {
$Document += "?rev=$Revision&new_edits=false"
$Revision = $null
Expand Down Expand Up @@ -5224,9 +5225,66 @@ function Remove-CouchDBAttachment () {
[Parameter(mandatory = $true)]
[string] $Revision,
[string] $Authorization,
[switch]$Force,
[switch] $Ssl
)
if ($Force -or $PSCmdlet.ShouldContinue("Do you wish remove attachment $Attachment in document $Document on database $Database ?", "Remove attachment $Attachment in document $Document on database $Database")) {
Send-CouchDBRequest -Server $Server -Port $Port -Method "DELETE" -Database $Database -Document $Document -Attachment $Attachment -Revision $Revision -Authorization $Authorization -Ssl:$Ssl
}
}

function Remove-CouchDBDesignDocumentAttachment () {
<#
.SYNOPSIS
Remove an attachment in a design document.
.DESCRIPTION
Deletes the attachment of the specified design document.
.NOTES
CouchDB API:
DELETE /{db}/_design/{ddoc}/{attname}
.PARAMETER Server
The CouchDB server name. Default is localhost.
.PARAMETER Port
The CouchDB server port. Default is 5984.
.PARAMETER Database
The CouchDB database.
.PARAMETER Document
The CouchDB document.
.PARAMETER Attachment
The CouchDB attachment document.
.PARAMETER Revision
The CouchDB revision document.
.PARAMETER Authorization
The CouchDB authorization form; user and password.
Authorization format like this: user:password
ATTENTION: if the password is not specified, it will be prompted.
.PARAMETER Ssl
Set ssl connection on CouchDB server.
This modify protocol to https and port to 6984.
.EXAMPLE
Remove-CouchDBDesignDocumentAttachment -Database test -Document "space" -Attachment test.txt -Revision "2-4705a219cdcca7c72aac4f623f5c46a8" -Authorization "admin:password"
The example removes an attachment "test.txt" on a design document "space" from database "test".
.LINK
https://pscouchdb.readthedocs.io/en/latest/documents.html#delete-an-attachment
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[string] $Server,
[int] $Port,
[Parameter(mandatory = $true, ValueFromPipeline = $true)]
[string] $Database,
[Parameter(mandatory = $true)]
[string] $Document,
[Parameter(mandatory = $true)]
[string] $Attachment,
[Parameter(mandatory = $true)]
[string] $Revision,
[string] $Authorization,
[switch]$Force,
[switch] $Ssl
)
if ($PSCmdlet.ShouldContinue("Do you wish remove attachment $Attachment in document $Document on database $Database ?", "Remove attachment $Attachment in document $Document on database $Database")) {
$Document = "_design/$Document"
if ($Force -or $PSCmdlet.ShouldContinue("Do you wish remove attachment $Attachment in design document $Document on database $Database ?", "Remove attachment $Attachment in design document $Document on database $Database")) {
Send-CouchDBRequest -Server $Server -Port $Port -Method "DELETE" -Database $Database -Document $Document -Attachment $Attachment -Revision $Revision -Authorization $Authorization -Ssl:$Ssl
}
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# The complete and powerfull powershell module for CouchDB v2.X
# The complete and powerful powershell module for CouchDB v2.X
[Powershell](https://github.com/PowerShell/PowerShell "Powershell source") meet [CouchDB](http://couchdb.apache.org/ "CouchDB site")

<img src="https://pscouchdb.readthedocs.io/en/latest/_images/pscouchdb-logo.png" alt="PSCouchDB" title="PSCouchDB" width="320" height="224" />
Expand Down
Binary file modified docs/build/doctrees/cmdlets.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/ddoc.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/build/doctrees/index.doctree
Binary file not shown.
9 changes: 8 additions & 1 deletion docs/build/html/_sources/cmdlets.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,12 @@ Design documents
Remove-CouchDBDesignDocument [[-Server] <String>] [[-Port] <Int32>] [-Database] <String> [-Document] <String> [-Revision] <String> [[-Authorization] <String>] [-Force] [-Ssl] [-WhatIf] [-Confirm] [<CommonParameters>]
**Remove-CouchDBDesignDocumentAttachment**

.. code-block:: powershell
Remove-CouchDBDesignDocumentAttachment [[-Server] <String>] [[-Port] <Int32>] [-Database] <String> [-Document] <String> [-Attachment] <String> [-Revision] <String> [[-Authorization] <String>] [-Ssl] [-WhatIf] [-Confirm] [<CommonParameters>]
Aliases
_______

Expand Down Expand Up @@ -611,7 +617,8 @@ _______
rcdb -> Remove-CouchDBDatabase
rcdbp -> Revoke-CouchDBDatabasePermission
rcdbr -> Request-CouchDBReplication
rcddoc -> Remove-CouchDBDesignDocument
rcddoc -> Remove-CouchDBDesignDocument
rdatt -> Remove-CouchDBDesignDocumentAttachment
rcdoc -> Remove-CouchDBDocument
rcidx -> Remove-CouchDBIndex
rcnode -> Remove-CouchDBNode
Expand Down
15 changes: 12 additions & 3 deletions docs/build/html/_sources/ddoc.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ To get all the Design Documents in a database.
Get-CouchDBDatabaseDesignDocument -Database test
Design document attachment
**************************
Get design document attachment
******************************

To retrieve or save an attachment in a design document.

Expand Down Expand Up @@ -203,4 +203,13 @@ To remove a design document.
.. code-block:: powershell
Remove-CouchDBDesignDocument -Database test -Document "mydesigndoc" -Revision "1-85a961d0d9b235b7b4f07baed1a38fda" -Authorization "admin:password"
Remove-CouchDBDesignDocument -Database test -Document "mydesigndoc" -Revision "1-85a961d0d9b235b7b4f07baed1a38fda" -Authorization "admin:password"
Remove design document attachment
*********************************
To modify or add an attachment in a design document.
.. code-block:: powershell
Remove-CouchDBDesignDocumentAttachment -Database test -Document space -Attachment "C:\test2.txt" -Revision 5-cfae778df80635ad15daa09e0264a988 -Authorization "admin:password"
2 changes: 1 addition & 1 deletion docs/build/html/_sources/index.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Welcome to PSCouchDB's documentation!
:align: center
:target: https://github.com/MatteoGuadrini/PSCouchDB

**The complete and powerfull powershell module for CouchDB v2.X**
**The complete and powerful powershell module for CouchDB v2.X**

.. raw:: html

Expand Down
5 changes: 5 additions & 0 deletions docs/build/html/cmdlets.html
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,10 @@ <h3>Design documents<a class="headerlink" href="#design-documents" title="Permal
<div class="highlight-powershell notranslate"><div class="highlight"><pre><span></span><span class="nb">Remove-CouchDBDesignDocument</span> <span class="p">[[</span><span class="n">-Server</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">String</span><span class="p">&gt;]</span> <span class="p">[[</span><span class="n">-Port</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">Int32</span><span class="p">&gt;]</span> <span class="p">[</span><span class="n">-Database</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">String</span><span class="p">&gt;</span> <span class="p">[</span><span class="n">-Document</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">String</span><span class="p">&gt;</span> <span class="p">[</span><span class="n">-Revision</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">String</span><span class="p">&gt;</span> <span class="p">[[</span><span class="n">-Authorization</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">String</span><span class="p">&gt;]</span> <span class="p">[</span><span class="n">-Force</span><span class="p">]</span> <span class="p">[</span><span class="n">-Ssl</span><span class="p">]</span> <span class="p">[</span><span class="n">-WhatIf</span><span class="p">]</span> <span class="p">[</span><span class="n">-Confirm</span><span class="p">]</span> <span class="p">[&lt;</span><span class="n">CommonParameters</span><span class="p">&gt;]</span>
</pre></div>
</div>
<p><strong>Remove-CouchDBDesignDocumentAttachment</strong></p>
<div class="highlight-powershell notranslate"><div class="highlight"><pre><span></span><span class="nb">Remove-CouchDBDesignDocumentAttachment</span> <span class="p">[[</span><span class="n">-Server</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">String</span><span class="p">&gt;]</span> <span class="p">[[</span><span class="n">-Port</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">Int32</span><span class="p">&gt;]</span> <span class="p">[</span><span class="n">-Database</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">String</span><span class="p">&gt;</span> <span class="p">[</span><span class="n">-Document</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">String</span><span class="p">&gt;</span> <span class="p">[</span><span class="n">-Attachment</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">String</span><span class="p">&gt;</span> <span class="p">[</span><span class="n">-Revision</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">String</span><span class="p">&gt;</span> <span class="p">[[</span><span class="n">-Authorization</span><span class="p">]</span> <span class="p">&lt;</span><span class="n">String</span><span class="p">&gt;]</span> <span class="p">[</span><span class="n">-Ssl</span><span class="p">]</span> <span class="p">[</span><span class="n">-WhatIf</span><span class="p">]</span> <span class="p">[</span><span class="n">-Confirm</span><span class="p">]</span> <span class="p">[&lt;</span><span class="n">CommonParameters</span><span class="p">&gt;]</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="aliases">
Expand Down Expand Up @@ -609,6 +613,7 @@ <h2>Aliases<a class="headerlink" href="#aliases" title="Permalink to this headli
<span class="n">rcdbp</span> <span class="p">-&gt;</span> <span class="n">Revoke-CouchDBDatabasePermission</span>
<span class="n">rcdbr</span> <span class="p">-&gt;</span> <span class="n">Request-CouchDBReplication</span>
<span class="n">rcddoc</span> <span class="p">-&gt;</span> <span class="nb">Remove-CouchDBDesignDocument</span>
<span class="n">rdatt</span> <span class="p">-&gt;</span> <span class="nb">Remove-CouchDBDesignDocumentAttachment</span>
<span class="n">rcdoc</span> <span class="p">-&gt;</span> <span class="nb">Remove-CouchDBDocument</span>
<span class="n">rcidx</span> <span class="p">-&gt;</span> <span class="nb">Remove-CouchDBIndex</span>
<span class="n">rcnode</span> <span class="p">-&gt;</span> <span class="nb">Remove-CouchDBNode</span>
Expand Down
18 changes: 14 additions & 4 deletions docs/build/html/ddoc.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<li class="toctree-l1"><a class="reference internal" href="documents.html#query">Query</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Design documents</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#get-a-design-document">Get a design document</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#design-document-attachment">Design document attachment</a></li>
<li class="toctree-l3"><a class="reference internal" href="#get-design-document-attachment">Get design document attachment</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#creates-a-design-document">Creates a design document</a><ul>
Expand All @@ -107,7 +107,10 @@
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#compress-design-document">Compress design document</a></li>
<li class="toctree-l2"><a class="reference internal" href="#remove-design-document">Remove design document</a></li>
<li class="toctree-l2"><a class="reference internal" href="#remove-design-document">Remove design document</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#remove-design-document-attachment">Remove design document attachment</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="cmdlets.html">Cmdlets and aliases</a></li>
Expand Down Expand Up @@ -195,8 +198,8 @@ <h2>Get a design document<a class="headerlink" href="#get-a-design-document" tit
<div class="highlight-powershell notranslate"><div class="highlight"><pre><span></span><span class="nb">Get-CouchDBDatabaseDesignDocument</span> <span class="n">-Database</span> <span class="n">test</span>
</pre></div>
</div>
<div class="section" id="design-document-attachment">
<h3>Design document attachment<a class="headerlink" href="#design-document-attachment" title="Permalink to this headline"></a></h3>
<div class="section" id="get-design-document-attachment">
<h3>Get design document attachment<a class="headerlink" href="#get-design-document-attachment" title="Permalink to this headline"></a></h3>
<p>To retrieve or save an attachment in a design document.</p>
<div class="highlight-powershell notranslate"><div class="highlight"><pre><span></span><span class="nb">Get-CouchDBDesignDocumentAttachment</span> <span class="n">-Database</span> <span class="n">test2</span> <span class="n">-Document</span> <span class="n">space</span> <span class="n">-Attachment</span> <span class="n">test</span><span class="p">.</span><span class="n">txt</span> <span class="n">-OutFile</span>
</pre></div>
Expand Down Expand Up @@ -333,6 +336,13 @@ <h2>Remove design document<a class="headerlink" href="#remove-design-document" t
<div class="highlight-powershell notranslate"><div class="highlight"><pre><span></span><span class="nb">Remove-CouchDBDesignDocument</span> <span class="n">-Database</span> <span class="n">test</span> <span class="n">-Document</span> <span class="s2">&quot;mydesigndoc&quot;</span> <span class="n">-Revision</span> <span class="s2">&quot;1-85a961d0d9b235b7b4f07baed1a38fda&quot;</span> <span class="n">-Authorization</span> <span class="s2">&quot;admin:password&quot;</span>
</pre></div>
</div>
<div class="section" id="remove-design-document-attachment">
<h3>Remove design document attachment<a class="headerlink" href="#remove-design-document-attachment" title="Permalink to this headline"></a></h3>
<p>To modify or add an attachment in a design document.</p>
<div class="highlight-powershell notranslate"><div class="highlight"><pre><span></span><span class="nb">Remove-CouchDBDesignDocumentAttachment</span> <span class="n">-Database</span> <span class="n">test</span> <span class="n">-Document</span> <span class="n">space</span> <span class="n">-Attachment</span> <span class="s2">&quot;C:\test2.txt&quot;</span> <span class="n">-Revision</span> <span class="n">5-cfae778df80635ad15daa09e0264a988</span> <span class="n">-Authorization</span> <span class="s2">&quot;admin:password&quot;</span>
</pre></div>
</div>
</div>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion docs/build/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ <h1>Welcome to PSCouchDB’s documentation!<a class="headerlink" href="#welcome-
<div class="figure align-center">
<a class="reference external image-reference" href="https://github.com/MatteoGuadrini/PSCouchDB"><img alt="_images/pscouchdb-logo.png" src="_images/pscouchdb-logo.png" style="width: 320px; height: 224px;" /></a>
</div>
<p><strong>The complete and powerfull powershell module for CouchDB v2.X</strong></p>
<p><strong>The complete and powerful powershell module for CouchDB v2.X</strong></p>
<script id="asciicast-232696" src="https://asciinema.org/a/232696.js" async></script><div class="toctree-wrapper compound">
<p class="caption"><span class="caption-text">Contents:</span></p>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion docs/build/html/searchindex.js

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion docs/source/cmdlets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,12 @@ Design documents
Remove-CouchDBDesignDocument [[-Server] <String>] [[-Port] <Int32>] [-Database] <String> [-Document] <String> [-Revision] <String> [[-Authorization] <String>] [-Force] [-Ssl] [-WhatIf] [-Confirm] [<CommonParameters>]
**Remove-CouchDBDesignDocumentAttachment**

.. code-block:: powershell
Remove-CouchDBDesignDocumentAttachment [[-Server] <String>] [[-Port] <Int32>] [-Database] <String> [-Document] <String> [-Attachment] <String> [-Revision] <String> [[-Authorization] <String>] [-Ssl] [-WhatIf] [-Confirm] [<CommonParameters>]
Aliases
_______

Expand Down Expand Up @@ -611,7 +617,8 @@ _______
rcdb -> Remove-CouchDBDatabase
rcdbp -> Revoke-CouchDBDatabasePermission
rcdbr -> Request-CouchDBReplication
rcddoc -> Remove-CouchDBDesignDocument
rcddoc -> Remove-CouchDBDesignDocument
rdatt -> Remove-CouchDBDesignDocumentAttachment
rcdoc -> Remove-CouchDBDocument
rcidx -> Remove-CouchDBIndex
rcnode -> Remove-CouchDBNode
Expand Down
15 changes: 12 additions & 3 deletions docs/source/ddoc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ To get all the Design Documents in a database.
Get-CouchDBDatabaseDesignDocument -Database test
Design document attachment
**************************
Get design document attachment
******************************

To retrieve or save an attachment in a design document.

Expand Down Expand Up @@ -203,4 +203,13 @@ To remove a design document.
.. code-block:: powershell
Remove-CouchDBDesignDocument -Database test -Document "mydesigndoc" -Revision "1-85a961d0d9b235b7b4f07baed1a38fda" -Authorization "admin:password"
Remove-CouchDBDesignDocument -Database test -Document "mydesigndoc" -Revision "1-85a961d0d9b235b7b4f07baed1a38fda" -Authorization "admin:password"
Remove design document attachment
*********************************
To modify or add an attachment in a design document.
.. code-block:: powershell
Remove-CouchDBDesignDocumentAttachment -Database test -Document space -Attachment "C:\test2.txt" -Revision 5-cfae778df80635ad15daa09e0264a988 -Authorization "admin:password"
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Welcome to PSCouchDB's documentation!
:align: center
:target: https://github.com/MatteoGuadrini/PSCouchDB

**The complete and powerfull powershell module for CouchDB v2.X**
**The complete and powerful powershell module for CouchDB v2.X**

.. raw:: html

Expand Down

0 comments on commit e6e9545

Please sign in to comment.